diff --git a/src/BootstrapBlazor.Shared/Locales/en.json b/src/BootstrapBlazor.Shared/Locales/en.json index aa290f70c50a233090081b52f485359b326b8967..0f930699a5dbd766b978fd65cc9096b73c10d452 100644 --- a/src/BootstrapBlazor.Shared/Locales/en.json +++ b/src/BootstrapBlazor.Shared/Locales/en.json @@ -808,6 +808,7 @@ "Att7": "Whether to turn on fuzzy matching", "Att8": "Whether case is ignored when matching", "Att9": "Custom collection filtering rules", + "Debounce": "Debounce interval default Zero", "SkipEnter": "Skip Enter key processing", "SkipEsc": "Skip Esc key processing", "OnSelectedItemChanged": "Callback for the selected item changed", diff --git a/src/BootstrapBlazor.Shared/Locales/zh.json b/src/BootstrapBlazor.Shared/Locales/zh.json index a727038a7bc5a53320071db7c333129232dd5b05..4f695a7770503f4084d0eeedb8503d779ad9d786 100644 --- a/src/BootstrapBlazor.Shared/Locales/zh.json +++ b/src/BootstrapBlazor.Shared/Locales/zh.json @@ -808,7 +808,7 @@ "Att7": "是否开启模糊匹配", "Att8": "匹配时是否忽略大小写", "Att9": "自定义集合过滤规则", - "Att10": "js 防抖时间,毫秒", + "Debounce": "js 防抖时间,毫秒", "SkipEnter": "是否跳过 Enter 按键处理", "SkipEsc": "是否跳过 Esc 按键处理", "OnSelectedItemChanged": "下拉菜单选择回调方法", diff --git a/src/BootstrapBlazor.Shared/Samples/AutoCompletes.razor.cs b/src/BootstrapBlazor.Shared/Samples/AutoCompletes.razor.cs index d32dce392a1db61a0e59f8b68e1cd81db5060d45..c7974f2c86cd57976f872fa335636c63e25c44c3 100644 --- a/src/BootstrapBlazor.Shared/Samples/AutoCompletes.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/AutoCompletes.razor.cs @@ -115,7 +115,7 @@ public sealed partial class AutoCompletes new AttributeItem() { Name = "Debounce", - Description = Localizer["Att10"], + Description = Localizer["Debounce"], Type = "int", ValueList = " — ", DefaultValue = "0" diff --git a/src/BootstrapBlazor.Shared/Samples/AutoFills.razor.cs b/src/BootstrapBlazor.Shared/Samples/AutoFills.razor.cs index e9eeca146dbcf05527692a5d2dceee9d72eeb63b..b06bad9c5855cb77c911338bc0e566382a7d55f0 100644 --- a/src/BootstrapBlazor.Shared/Samples/AutoFills.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/AutoFills.razor.cs @@ -91,6 +91,14 @@ partial class AutoFills ValueList = " — ", DefaultValue = " — " }, + new AttributeItem() + { + Name = "Debounce", + Description = "防抖时间", + Type = "int", + ValueList = " — ", + DefaultValue = "0" + }, new AttributeItem() { Name = "OnCustomFilter", Description = "自定义集合过滤规则", diff --git a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs index d2bf413552b36a2e62b1bca93df1cf8e381fef93..82cd3080a7eccef127ffe3328a789cc0adea2c31 100644 --- a/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs +++ b/src/BootstrapBlazor/Components/AutoFill/AutoFill.razor.cs @@ -100,6 +100,12 @@ public partial class AutoFill [Parameter] public Func? OnSelectedItemChanged { get; set; } + /// + /// 获得/设置 防抖时间 默认为 0 即不开启 + /// + [Parameter] + public int Debounce { get; set; } + /// /// /// @@ -148,6 +154,14 @@ public partial class AutoFill { await JSRuntime.InvokeVoidAsync(AutoFillElement, "bb_autoScrollItem", CurrentItemIndex.Value); } + + if (firstRender) + { + if (Debounce > 0) + { + await JSRuntime.InvokeVoidAsync(AutoFillElement, "bb_setDebounce", Debounce); + } + } } /// diff --git a/test/UnitTest/Components/AutoFillTest.cs b/test/UnitTest/Components/AutoFillTest.cs index 3c4b10ba962c2d8b46112e38b42900eaa270299b..1e20382ce1d743a5839efe6202b3aa98c12ca73f 100644 --- a/test/UnitTest/Components/AutoFillTest.cs +++ b/test/UnitTest/Components/AutoFillTest.cs @@ -193,7 +193,7 @@ public class AutoFillTest : BootstrapBlazorTestBase pb.Add(a => a.Template, v => builder => { builder.OpenElement(0, "div"); - builder.AddContent(1, v?.Value); + builder.AddContent(1, v!.Value); builder.CloseElement(); }); }); @@ -214,6 +214,17 @@ public class AutoFillTest : BootstrapBlazorTestBase Assert.Equal(2, cut.FindAll(".dropdown-item").Count); } + [Fact] + public void Debounce_Ok() + { + var cut = Context.RenderComponent>(pb => + { + pb.Add(a => a.Value, Model); + pb.Add(a => a.Items, Items); + pb.Add(a => a.Debounce, 200); + }); + } + class AutoFillNullStringMock { [NotNull]