Skip to content

Commit 3508958

Browse files
cwtalentkonw_nothingArgoZhang
authored
fix(Select): prevent value changing on external StateHasChanged (#7618)
* fix: Select component value incorrectly changes when external StateHasChanged is called during search * chore: bump version 10.3.1-beta06 --------- Co-authored-by: konw_nothing <13763803956@chinalco.com.cn> Co-authored-by: Argo Zhang <argo@live.ca>
1 parent eb6dad4 commit 3508958

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

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>10.3.1-beta05</Version>
4+
<Version>10.3.1-beta06</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/Select/Select.razor.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,14 @@ private async Task OnChange(ChangeEventArgs args)
491491

492492
private SelectedItem? GetItemByRows()
493493
{
494+
// 修复:使用完整的未过滤列表来查找当前选中项
495+
// 避免在用户搜索时被外部 StateHasChanged 影响导致值被错误修改
496+
var allItems = GetRowsByItems();
497+
494498
var item = GetItemWithEnumValue()
495-
?? Rows.Find(i => i.Value == CurrentValueAsString)
496-
?? Rows.Find(i => i.Active)
497-
?? Rows.Find(i => !i.IsDisabled);
499+
?? allItems.Find(i => i.Value == CurrentValueAsString)
500+
?? allItems.Find(i => i.Active)
501+
?? allItems.Find(i => !i.IsDisabled);
498502
return item;
499503
}
500504
}

0 commit comments

Comments
 (0)