Skip to content

Commit 751bc91

Browse files
committed
feat: 增加客户端防抖
1 parent d4adda1 commit 751bc91

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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) {

0 commit comments

Comments
 (0)