Skip to content

Commit c6156a8

Browse files
authored
feat: #326
1 parent 3369532 commit c6156a8

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/components/ui-lib.module.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@
323323
border: none;
324324
outline: none;
325325
font-size: 14px;
326+
text-align: left;
326327
}
327328

328329
&-search-input:focus {

app/components/ui-lib.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,14 +503,27 @@ export function SearchSelector<T>(props: {
503503
}
504504
};
505505

506+
const { items, onClose } = props;
506507
// 过滤列表项
507-
const filteredItems = props.items.filter(
508+
const filteredItems = items.filter(
508509
(item) =>
509510
item.title.toLowerCase().includes(searchQuery.toLowerCase()) ||
510511
(item.subTitle &&
511512
item.subTitle.toLowerCase().includes(searchQuery.toLowerCase())),
512513
);
513514

515+
useEffect(() => {
516+
const handleKeyDown = (event: KeyboardEvent) => {
517+
if (event.key === "Escape") {
518+
onClose?.();
519+
}
520+
};
521+
document.addEventListener("keydown", handleKeyDown);
522+
return () => {
523+
document.removeEventListener("keydown", handleKeyDown);
524+
};
525+
}, [onClose]);
526+
514527
return (
515528
<div className={styles["selector"]} onClick={() => props.onClose?.()}>
516529
<div
@@ -522,6 +535,7 @@ export function SearchSelector<T>(props: {
522535
<div className={styles["selector-search"]}>
523536
<input
524537
type="text"
538+
autoFocus
525539
className={styles["selector-search-input"]}
526540
placeholder="search model"
527541
value={searchQuery}

0 commit comments

Comments
 (0)