Skip to content

Commit 4a86773

Browse files
author
konw_nothing
committed
fix: Select component value incorrectly changes when external StateHasChanged is called during search
1 parent 3445b76 commit 4a86773

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

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)