diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index 68c1d989b03..917abf50715 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@  - 9.10.1 + 9.10.2 diff --git a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor index 40e29d49717..06b00d221f7 100644 --- a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor +++ b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor @@ -19,7 +19,7 @@ @if (GetClearable()) { - + } @RenderDropdown diff --git a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs index 6da99c45d14..10690174c5b 100644 --- a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs +++ b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs @@ -14,13 +14,6 @@ namespace BootstrapBlazor.Components; /// The type of the value. public partial class AutoFill { - /// - /// Gets the component style. - /// - private string? ClassString => CssBuilder.Default("auto-complete auto-fill") - .AddClass("is-clearable", IsClearable) - .Build(); - /// /// Gets or sets the collection of items for the component. /// @@ -141,6 +134,13 @@ public partial class AutoFill [NotNull] private RenderTemplate? _dropdown = null; + /// + /// Gets the component style. + /// + private string? ClassString => CssBuilder.Default("auto-complete auto-fill") + .AddClass("is-clearable", IsClearable) + .Build(); + /// /// Gets the clear icon class string. /// @@ -176,7 +176,6 @@ protected override void OnParametersSet() /// protected override Task InvokeInitAsync() => InvokeVoidAsync("init", Id, Interop, _displayText); - private bool IsNullable() => !ValueType.IsValueType || NullableUnderlyingType != null; /// @@ -185,30 +184,6 @@ protected override void OnParametersSet() /// private bool GetClearable() => IsClearable && !IsDisabled && IsNullable(); - /// - /// - /// - /// - private async Task OnClearValue() - { - // 使用脚本更新 input 值 - await InvokeVoidAsync("setValue", Id, ""); - - if (OnClearAsync != null) - { - await OnClearAsync(); - } - CurrentValue = default; - _displayText = null; - _filterItems = null; - _searchText = null; - - if (OnQueryAsync != null) - { - await _virtualizeElement.RefreshDataAsync(); - } - } - /// /// Callback method when a candidate item is clicked. /// @@ -255,6 +230,18 @@ private async ValueTask> LoadItems(ItemsProviderRequ [JSInvokable] public async Task TriggerFilter(string val) { + if (string.IsNullOrEmpty(val)) + { + CurrentValue = default; + _filterItems = null; + _displayText = null; + + if (OnClearAsync != null) + { + await OnClearAsync(); + } + } + if (OnQueryAsync != null) { _searchText = val; diff --git a/test/UnitTest/Components/AutoFillTest.cs b/test/UnitTest/Components/AutoFillTest.cs index ed6f39cdc86..6f7cf04c9a9 100644 --- a/test/UnitTest/Components/AutoFillTest.cs +++ b/test/UnitTest/Components/AutoFillTest.cs @@ -425,10 +425,9 @@ public async Task IsVirtualize_OnQueryAsync_Clearable_Ok() Assert.Equal("2", searchText); Assert.Contains("
test2
", cut.Markup); + // 测试 Clear 清空逻辑 query = false; - // 点击 Clear 按钮 - var button = cut.Find(".clear-icon"); - await cut.InvokeAsync(() => button.Click()); + await cut.InvokeAsync(() => cut.Instance.TriggerFilter("")); Assert.True(query); Assert.True(cleared); @@ -445,7 +444,7 @@ public async Task IsVirtualize_OnQueryAsync_Clearable_Ok() }); }); }); - await cut.InvokeAsync(() => button.Click()); + await cut.InvokeAsync(() => cut.Instance.TriggerFilter("")); } [Fact]