From e2f0e3e152197bc690360d0573abf18420fcc476 Mon Sep 17 00:00:00 2001 From: celadaris Date: Wed, 5 Mar 2025 13:48:25 -0600 Subject: [PATCH 1/3] Update AutoComplete.razor.cs fixes the same problem I was having in issue #5110 --- .../AutoComplete/AutoComplete.razor.cs | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs index 7e8be6d5e65..dd0fb7ae2c0 100644 --- a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs +++ b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs @@ -135,6 +135,9 @@ private async Task OnClickItem(string val) [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); @@ -152,12 +155,20 @@ public override async Task TriggerFilter(string val) : Items.Where(s => s.StartsWith(val, comparison)); _filterItems = [.. items]; } - + if (DisplayCount != null) { _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(); + } } /// @@ -167,10 +178,15 @@ public override async Task TriggerFilter(string val) [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; } From 25983fd3a209d617b5e9e7f746257d6b1f248cfa Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 6 Mar 2025 08:28:02 +0800 Subject: [PATCH 2/3] chore: bump version 9.4.7-beta01 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 032815c679d54301248a39ef9b45c374fae8558f Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Thu, 6 Mar 2025 08:33:10 +0800 Subject: [PATCH 3/3] doc: update comment to english --- .../AutoComplete/AutoComplete.razor.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs b/src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.cs index dd0fb7ae2c0..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,7 +129,7 @@ private async Task OnClickItem(string val) private List Rows => _filterItems ?? [.. Items]; /// - /// TriggerFilter 方法 + /// TriggerFilter method /// /// [JSInvokable] @@ -137,7 +137,7 @@ 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); @@ -155,15 +155,15 @@ public override async Task TriggerFilter(string val) : Items.Where(s => s.StartsWith(val, comparison)); _filterItems = [.. items]; } - + if (DisplayCount != null) { _filterItems = [.. _filterItems.Take(DisplayCount.Value)]; } - + // Use currentInputValue here instead of potentially stale val CurrentValue = currentInputValue; - + // Only trigger StateHasChanged if no binding is present if (!ValueChanged.HasDelegate) { @@ -172,7 +172,7 @@ public override async Task TriggerFilter(string val) } /// - /// TriggerChange 方法 + /// TriggerChange method /// /// [JSInvokable]