diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index e4ca825a58a..4b1d7754056 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.4.6 + 9.4.7-beta01 diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs index 7e8be6d5e65..1d9f4e5e50d 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs @@ -8,82 +8,82 @@ namespace BootstrapBlazor.Components; /// -/// AutoComplete 组件 +/// AutoComplete component /// public partial class AutoComplete { /// - /// 获得 组件样式 + /// Gets the component style /// private string? ClassString => CssBuilder.Default("auto-complete") .AddClassFromAttributes(AdditionalAttributes) .Build(); /// - /// 获得/设置 通过输入字符串获得匹配数据集合 + /// Gets or sets the collection of matching data obtained by inputting a string /// [Parameter] [NotNull] public IEnumerable? Items { get; set; } /// - /// 获得/设置 自定义集合过滤规则 默认 null + /// Gets or sets custom collection filtering rules, default is null /// [Parameter] public Func>>? OnCustomFilter { get; set; } /// - /// 获得/设置 图标 + /// Gets or sets the icon /// [Parameter] public string? Icon { get; set; } /// - /// 获得/设置 加载图标 + /// Gets or sets the loading icon /// [Parameter] public string? LoadingIcon { get; set; } /// - /// 获得/设置 匹配数据时显示的数量 + /// Gets or sets the number of items to display when matching data /// [Parameter] [NotNull] public int? DisplayCount { get; set; } /// - /// 获得/设置 是否开启模糊查询,默认为 false + /// Gets or sets whether to enable fuzzy search, default is false /// [Parameter] public bool IsLikeMatch { get; set; } /// - /// 获得/设置 匹配时是否忽略大小写,默认为 true + /// Gets or sets whether to ignore case when matching, default is true /// [Parameter] public bool IgnoreCase { get; set; } = true; /// - /// 获得/设置 获得焦点时是否展开下拉候选菜单 默认 true + /// Gets or sets whether to expand the dropdown candidate menu when focused, default is true /// [Parameter] public bool ShowDropdownListOnFocus { get; set; } = true; /// - /// 获得/设置 是否显示无匹配数据选项 默认 true 显示 + /// Gets or sets whether to show the no matching data option, default is true /// [Parameter] public bool ShowNoDataTip { get; set; } = true; /// - /// IStringLocalizer 服务实例 + /// IStringLocalizer service instance /// [Inject] [NotNull] private IStringLocalizer? Localizer { get; set; } /// - /// 获得 获得焦点自动显示下拉框设置字符串 + /// Gets the string setting for automatically displaying the dropdown when focused /// private string? ShowDropdownListOnFocusString => ShowDropdownListOnFocus ? "true" : null; @@ -115,7 +115,7 @@ protected override void OnParametersSet() } /// - /// 鼠标点击候选项时回调此方法 + /// Callback method when a candidate item is clicked /// private async Task OnClickItem(string val) { @@ -129,12 +129,15 @@ private async Task OnClickItem(string val) private List Rows => _filterItems ?? [.. Items]; /// - /// TriggerFilter 方法 + /// TriggerFilter method /// /// [JSInvokable] public override async Task TriggerFilter(string val) { + // Store the current input value to prevent it from being overwritten + var currentInputValue = val; + if (OnCustomFilter != null) { var items = await OnCustomFilter(val); @@ -157,20 +160,33 @@ public override async Task TriggerFilter(string val) { _filterItems = [.. _filterItems.Take(DisplayCount.Value)]; } - await TriggerChange(val); + + // Use currentInputValue here instead of potentially stale val + CurrentValue = currentInputValue; + + // Only trigger StateHasChanged if no binding is present + if (!ValueChanged.HasDelegate) + { + StateHasChanged(); + } } /// - /// TriggerChange 方法 + /// TriggerChange method /// /// [JSInvokable] public override Task TriggerChange(string val) { - CurrentValue = val; - if (!ValueChanged.HasDelegate) + // Only update CurrentValue if the value has actually changed + // This prevents overwriting the user's input + if (CurrentValue != val) { - StateHasChanged(); + CurrentValue = val; + if (!ValueChanged.HasDelegate) + { + StateHasChanged(); + } } return Task.CompletedTask; }