@@ -68,7 +68,6 @@ const STATIC_PROPS =
6868 } ,
6969 PopperComponent,
7070 onChange : handleChange ,
71- renderInput,
7271 renderOption,
7372 autoComplete : false ,
7473 clearOnBlur : false ,
@@ -83,18 +82,41 @@ export function Search() {
8382
8483 const { t } = useTranslation ( )
8584
85+ /** @type {React.MutableRefObject<HTMLInputElement | null> } */
86+ const inputRef = React . useRef ( null )
87+
8688 const search = useStorage ( ( s ) => s . search )
8789 const isMobile = useMemory ( ( s ) => s . isMobile )
8890 const open = useLayoutStore ( ( s ) => s . search )
8991
9092 const { loading, options, handleInputChange } = useSendSearch ( search , open )
9193
94+ const handleDialogEntered = React . useCallback ( ( ) => {
95+ if ( inputRef . current ) {
96+ inputRef . current . focus ( )
97+ }
98+ } , [ ] )
99+
100+ React . useEffect ( ( ) => {
101+ if ( ! open ) {
102+ return undefined
103+ }
104+ const frame = requestAnimationFrame ( ( ) => {
105+ if ( inputRef . current ) {
106+ inputRef . current . focus ( )
107+ }
108+ } )
109+ return ( ) => cancelAnimationFrame ( frame )
110+ } , [ open ] )
111+
92112 return (
93113 < Dialog
94114 fullScreen = { isMobile }
95115 open = { open }
96116 onClose = { handleClose }
117+ disableAutoFocus
97118 sx = { DIALOG_SX }
119+ TransitionProps = { { onEntered : handleDialogEntered } }
98120 >
99121 < Box width = { BOX_WIDTH } >
100122 < Header titles = "search" action = { handleClose } />
@@ -106,6 +128,7 @@ export function Search() {
106128 loading = { loading }
107129 loadingText = { t ( 'searching' ) }
108130 noOptionsText = { t ( 'no_options' ) }
131+ renderInput = { ( params ) => renderInput ( params , inputRef ) }
109132 { ...STATIC_PROPS }
110133 />
111134 </ Box >
0 commit comments