Skip to content

Commit

Permalink
fix(Select): not trigger OnSelectedItemChanged when click clear icon (#…
Browse files Browse the repository at this point in the history
…4283)

* fix: 清空搜索栏触发 SelectedItemChanged 回调方法

* chore: bump version 8.9.2-beta07

* test: 更新单元测试
  • Loading branch information
ArgoZhang authored Sep 12, 2024
1 parent 7dd6a2b commit ec6cb2a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>8.9.2-beta06</Version>
<Version>8.9.2-beta07</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
Expand Down
7 changes: 6 additions & 1 deletion src/BootstrapBlazor/Components/Select/Select.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,12 @@ private async Task OnClearValue()
{
await OnClearAsync();
}
CurrentValue = default;

var item = DataSource.FirstOrDefault();
if (item != null)
{
await SelectedItemChanged(item);
}
}

private string? ReadonlyString => IsEditable ? null : "readonly";
Expand Down
4 changes: 2 additions & 2 deletions test/UnitTest/Components/SelectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void IsClearable_Ok()
new("2", "Test2"),
new("3", "Test3")
});
pb.Add(a => a.Value, "");
pb.Add(a => a.Value, "2");
pb.Add(a => a.OnValueChanged, v =>
{
val = v;
Expand All @@ -106,7 +106,7 @@ public void IsClearable_Ok()
});
var clearButton = cut.Find(".clear-icon");
cut.InvokeAsync(() => clearButton.Click());
Assert.Null(val);
Assert.Empty(val);

// 提高代码覆盖率
var select = cut;
Expand Down

0 comments on commit ec6cb2a

Please sign in to comment.