This commit is contained in:
Hk-Gosuto 2024-12-10 04:12:13 +00:00 committed by GitHub
parent 3369532af9
commit c6156a8d8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 1 deletions

View File

@ -323,6 +323,7 @@
border: none;
outline: none;
font-size: 14px;
text-align: left;
}
&-search-input:focus {

View File

@ -503,14 +503,27 @@ export function SearchSelector<T>(props: {
}
};
const { items, onClose } = props;
// 过滤列表项
const filteredItems = props.items.filter(
const filteredItems = items.filter(
(item) =>
item.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
(item.subTitle &&
item.subTitle.toLowerCase().includes(searchQuery.toLowerCase())),
);
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === "Escape") {
onClose?.();
}
};
document.addEventListener("keydown", handleKeyDown);
return () => {
document.removeEventListener("keydown", handleKeyDown);
};
}, [onClose]);
return (
<div className={styles["selector"]} onClick={() => props.onClose?.()}>
<div
@ -522,6 +535,7 @@ export function SearchSelector<T>(props: {
<div className={styles["selector-search"]}>
<input
type="text"
autoFocus
className={styles["selector-search-input"]}
placeholder="search model"
value={searchQuery}