fix: through collection support search (#3800)

This commit is contained in:
katherinehhh 2024-03-22 23:08:17 +08:00 committed by GitHub
parent cef18eb979
commit 4f0907be1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -325,6 +325,17 @@ export const ThroughCollection = observer(
setInitialValue(option?.label || value);
}
}, []);
const handleSearch = (value: string) => {
if (value) {
const filteredOptions = options.filter((option) => {
return option.label.toLowerCase().includes(value.toLowerCase());
});
setOptions(filteredOptions);
} else {
const data = loadCollections();
setOptions(data);
}
};
return (
<div>
<AutoComplete
@ -333,9 +344,10 @@ export const ThroughCollection = observer(
popupMatchSelectWidth={false}
value={initialValue}
options={options}
onSearch={handleSearch}
onChange={(value, option) => {
props?.onChange?.(value);
setInitialValue(option.label);
setInitialValue(option.label || value);
}}
/>
</div>