Skip to content

Commit 61eefd1

Browse files
authored
feat(Search): support Debounce default value 200ms (#5308)
* feat: 增加客户端防抖 * feat: 增加防抖参数设置 * doc: 增加防抖 200 毫秒设置 * feat: 增加防抖默认值 200
1 parent 528f80a commit 61eefd1

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/BootstrapBlazor.Server/Components/Samples/Searches.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ private async Task OnClickClear()
186186
<div class="row g-3">
187187
<div class="col-12 col-sm-6">
188188
<Search PlaceHolder="@Localizer["SearchesPlaceHolder"]"
189-
OnSearch="@OnModelSearch"
189+
OnSearch="@OnModelSearch" Debounce="200"
190190
IsClearable="_isClearable" ShowClearButton="_showClearButton" ShowSearchButton="_showSearchButton"
191191
ShowPrefixIcon="true" PrefixIcon="fa-brands fa-github">
192192
</Search>

src/BootstrapBlazor/Components/AutoComplete/AutoComplete.razor.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,23 @@ export function init(id, invoke) {
5858
invoke.invokeMethodAsync('TriggerChange', e.target.value);
5959
});
6060

61-
Input.composition(input, async v => {
61+
let filterDuration = duration;
62+
if (filterDuration === 0) {
63+
filterDuration = 200;
64+
}
65+
const filterCallback = debounce(async v => {
66+
await invoke.invokeMethodAsync('TriggerFilter', v);
67+
el.classList.remove('is-loading');
68+
}, filterDuration);
69+
70+
Input.composition(input, v => {
6271
const useInput = input.getAttribute('data-bb-input') !== 'false';
6372
if (isPopover === false && useInput) {
6473
el.classList.add('show');
6574
}
6675

6776
el.classList.add('is-loading');
68-
await invoke.invokeMethodAsync('TriggerFilter', v);
69-
el.classList.remove('is-loading');
77+
filterCallback(v);
7078
});
7179

7280
if (window.BootstrapBlazor.AutoComplete === void 0) {

src/BootstrapBlazor/Components/Search/Search.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
<input id="@InputId" class="search-input" autocomplete="off" type="text"
2626
data-bs-toggle="@ToggleString" data-bs-placement="@PlacementString"
2727
data-bs-offset="@OffsetString" data-bs-custom-class="@CustomClassString"
28-
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString"
28+
data-bb-auto-dropdown-focus="@ShowDropdownListOnFocusString" data-bb-debounce="@DurationString"
2929
data-bb-skip-esc="@SkipEscString" data-bb-skip-enter="@SkipEnterString"
3030
data-bb-scroll-behavior="@ScrollIntoViewBehaviorString"
3131
data-bb-input="@UseInputString"

src/BootstrapBlazor/Components/Search/Search.razor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ protected override void OnParametersSet()
198198
ButtonIcon ??= SearchButtonIcon;
199199
NoDataTip ??= Localizer[nameof(NoDataTip)];
200200
_filterItems ??= [];
201+
202+
if (Debounce == 0)
203+
{
204+
Debounce = 200;
205+
}
201206
}
202207

203208
private string _displayText = "";

0 commit comments

Comments
 (0)