@@ -30,7 +30,7 @@ export default function usePickerInput({
3030 onFocus ?: React . FocusEventHandler < HTMLInputElement > ;
3131 onBlur ?: React . FocusEventHandler < HTMLInputElement > ;
3232 currentFocusedKey ?: React . MutableRefObject < string > ;
33- key : string ;
33+ key ? : string ;
3434} ) : [ React . DOMAttributes < HTMLInputElement > , { focused : boolean ; typing : boolean } ] {
3535 const [ typing , setTyping ] = useState ( false ) ;
3636 const [ focused , setFocused ] = useState ( false ) ;
@@ -104,7 +104,9 @@ export default function usePickerInput({
104104 setTyping ( true ) ;
105105 setFocused ( true ) ;
106106
107- currentFocusedKey . current = key ;
107+ if ( currentFocusedKey ) {
108+ currentFocusedKey . current = key ;
109+ }
108110 clearTimeout ( delayBlurTimer . current ) ;
109111 if ( onFocus ) {
110112 onFocus ( e ) ;
@@ -136,16 +138,19 @@ export default function usePickerInput({
136138 }
137139 }
138140 setFocused ( false ) ;
139-
140- currentFocusedKey . current = '' ;
141- // Delay to prevent 'range' focus transitions from firing resulting in incorrect out-of-focus events
142- delayBlurTimer . current = setTimeout ( ( ) => {
143- // Prevent the 'blur' event from firing when there is currently a focused input
144- if ( currentFocusedKey . current ) return ;
145- if ( onBlur ) {
146- onBlur ( e ) ;
147- }
148- } , 100 ) ;
141+ if ( currentFocusedKey ) {
142+ currentFocusedKey . current = '' ;
143+ // Delay to prevent 'range' focus transitions from firing resulting in incorrect out-of-focus events
144+ delayBlurTimer . current = setTimeout ( ( ) => {
145+ // Prevent the 'blur' event from firing when there is currently a focused input
146+ if ( currentFocusedKey . current ) {
147+ return ;
148+ }
149+ onBlur ?.( e ) ;
150+ } , 100 ) ;
151+ } else {
152+ onBlur ?.( e ) ;
153+ }
149154 } ,
150155 } ;
151156
0 commit comments