Skip to content

Commit ab2a546

Browse files
authored
fix(Cascade): display incorrect when set Items async (#6954)
* fix: 修复数据源为 null 时赋值逻辑 * chore: bump version 9.11.3-beta05 * test: 增加单元测试
1 parent 313b0ba commit ab2a546

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

src/BootstrapBlazor/BootstrapBlazor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.11.3-beta04</Version>
4+
<Version>9.11.3-beta05</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Cascader/Cascader.razor.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,16 @@ protected override void OnParametersSet()
133133
SubMenuIcon ??= IconTheme.GetIconByKey(ComponentIcons.CascaderSubMenuIcon);
134134
ClearIcon ??= IconTheme.GetIconByKey(ComponentIcons.SelectClearIcon);
135135

136-
Items ??= [];
137-
138136
PlaceHolder ??= Localizer[nameof(PlaceHolder)];
139137

138+
Items ??= [];
139+
if (!Items.Any())
140+
{
141+
_lastValue = string.Empty;
142+
Value = default;
143+
return;
144+
}
145+
140146
if (_lastValue != CurrentValueAsString)
141147
{
142148
_lastValue = CurrentValueAsString;

test/UnitTest/Components/CascaderTest.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,16 @@ public void SetDefaultValue_Ok()
173173
pb.Add(a => a.Value, "1");
174174
pb.Add(a => a.ShowFullLevels, false);
175175
});
176-
Assert.Empty(cut.Instance.Value);
176+
177+
// 未提供数据源时 Value 赋值无效
178+
Assert.Null(cut.Instance.Value);
179+
180+
cut.SetParametersAndRender(pb =>
181+
{
182+
pb.Add(a => a.Items, items);
183+
pb.Add(a => a.Value, "3");
184+
pb.Add(a => a.ShowFullLevels, false);
185+
});
177186
}
178187

179188
[Fact]

0 commit comments

Comments
 (0)