Skip to content

Commit

Permalink
Merge pull request #1389 from easyops-cn/steve/fix-v3-bricks
Browse files Browse the repository at this point in the history
fix(eo-select): search event respects debounceSearchDelay
  • Loading branch information
WHChen-Alex authored Nov 5, 2024
2 parents 4452408 + 0525a9c commit 27b3495
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions bricks/form/src/select/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ class Select extends FormItemElementBase {
})
accessor useBackend: UseBackendConf | undefined;

/**
* 设置时,同时对 useBackend 和 search 事件进行防抖。
* 未设置时,useBackend 有默认的 300ms 防抖。
*/
@property({
type: Number,
})
Expand Down Expand Up @@ -349,6 +353,12 @@ export function SelectComponent(props: SelectProps) {
onSearch,
} = props;

const debouncedOnSearch = useMemo(() => {
return debounceSearchDelay
? debounce(onSearch!, debounceSearchDelay)
: onSearch;
}, [debounceSearchDelay, onSearch]);

const multiple = useMemo(
() => mode && ["multiple", "tags"].includes(mode),
[mode]
Expand Down Expand Up @@ -568,11 +578,17 @@ export function SelectComponent(props: SelectProps) {
} else {
setInputValue(value);
setIsDropHidden(false);
onSearch?.(value);
debouncedOnSearch!(value);
}
handleDebounceBackendSearch(value, "search");
},
[handleChange, handleDebounceBackendSearch, mode, onSearch, tokenSeparators]
[
handleChange,
handleDebounceBackendSearch,
mode,
debouncedOnSearch,
tokenSeparators,
]
);

const handleKeydown = useCallback(
Expand Down

0 comments on commit 27b3495

Please sign in to comment.