File tree Expand file tree Collapse file tree 1 file changed +8
-6
lines changed
resources/scripts/components/dashboard/search Expand file tree Collapse file tree 1 file changed +8
-6
lines changed Original file line number Diff line number Diff line change @@ -63,22 +63,24 @@ export default ({ ...props }: Props) => {
6363 console . error ( error ) ;
6464 addError ( { key : 'search' , message : httpErrorToHuman ( error ) } ) ;
6565 } )
66- . then ( ( ) => setLoading ( false ) ) ;
66+ . then ( ( ) => setLoading ( false ) )
67+ . then ( ( ) => ref . current ?. focus ( ) ) ;
6768 } , 500 ) ;
6869
6970 useEffect ( ( ) => {
7071 if ( props . visible ) {
71- setTimeout ( ( ) => ref . current ? .focus ( ) , 250 ) ;
72+ if ( ref . current ) ref . current . focus ( ) ;
7273 }
7374 } , [ props . visible ] ) ;
7475
76+ // Formik does not support an innerRef on custom components.
77+ const InputWithRef = ( props : any ) => < Input { ...props } ref = { ref } /> ;
78+
7579 return (
7680 < Formik
7781 onSubmit = { search }
7882 validationSchema = { object ( ) . shape ( {
79- term : string ( )
80- . min ( 3 , 'Please enter at least three characters to begin searching.' )
81- . required ( 'A search term must be provided.' ) ,
83+ term : string ( ) . min ( 3 , 'Please enter at least three characters to begin searching.' ) ,
8284 } ) }
8385 initialValues = { { term : '' } as Values }
8486 >
@@ -95,7 +97,7 @@ export default ({ ...props }: Props) => {
9597 >
9698 < SearchWatcher />
9799 < InputSpinner visible = { loading } >
98- < Field as = { Input } innerRef = { ref } name = { 'term' } />
100+ < Field as = { InputWithRef } name = { 'term' } />
99101 </ InputSpinner >
100102 </ FormikFieldWrapper >
101103 </ Form >
You can’t perform that action at this time.
0 commit comments