@@ -13,6 +13,7 @@ export default function usePickerInput({
13
13
onKeyDown,
14
14
blurToCancel,
15
15
changeOnBlur,
16
+ hasExtraFooter,
16
17
onSubmit,
17
18
onCancel,
18
19
onFocus,
@@ -25,14 +26,16 @@ export default function usePickerInput({
25
26
forwardKeyDown : ( e : React . KeyboardEvent < HTMLInputElement > ) => boolean ;
26
27
onKeyDown : ( e : React . KeyboardEvent < HTMLInputElement > , preventDefault : ( ) => void ) => void ;
27
28
blurToCancel ?: boolean ;
28
- changeOnBlur ?: boolean
29
+ changeOnBlur ?: boolean ;
30
+ hasExtraFooter ?: boolean ;
29
31
onSubmit : ( ) => void | boolean ;
30
32
onCancel : ( ) => void ;
31
33
onFocus ?: React . FocusEventHandler < HTMLInputElement > ;
32
34
onBlur ?: React . FocusEventHandler < HTMLInputElement > ;
33
35
} ) : [ React . DOMAttributes < HTMLInputElement > , { focused : boolean ; typing : boolean } ] {
34
36
const [ typing , setTyping ] = useState ( false ) ;
35
37
const [ focused , setFocused ] = useState ( false ) ;
38
+ const [ outside , setOutside ] = useState ( true ) ;
36
39
37
40
/**
38
41
* We will prevent blur to handle open event when user click outside,
@@ -108,7 +111,7 @@ export default function usePickerInput({
108
111
} ,
109
112
110
113
onBlur : ( e ) => {
111
- if ( preventBlurRef . current || ! isClickOutside ( document . activeElement ) ) {
114
+ if ( preventBlurRef . current || ! isClickOutside ( document . activeElement ) || ! outside ) {
112
115
preventBlurRef . current = false ;
113
116
return ;
114
117
}
@@ -152,6 +155,11 @@ export default function usePickerInput({
152
155
const target = getTargetFromEvent ( e ) ;
153
156
const clickedOutside = isClickOutside ( target ) ;
154
157
158
+ if ( hasExtraFooter ) {
159
+ // Save whether the last click is inside the component when `extraFooter` exists.
160
+ setOutside ( clickedOutside ) ;
161
+ }
162
+
155
163
if ( open ) {
156
164
if ( ! clickedOutside ) {
157
165
preventBlurRef . current = true ;
0 commit comments