File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 323323 border : none ;
324324 outline : none ;
325325 font-size : 14px ;
326+ text-align : left ;
326327 }
327328
328329 & -search-input :focus {
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments