Skip to content

Commit 3e0214f

Browse files
kiner-tangtangwenhuiafc163
authored
fix: key should be a optional param (#514)
* fix: key should be a optional param * fix: key should be a optional param * fix: code optimize * Update src/hooks/usePickerInput.ts Co-authored-by: afc163 <[email protected]> * Update src/hooks/usePickerInput.ts Co-authored-by: afc163 <[email protected]> * Update src/hooks/usePickerInput.ts Co-authored-by: afc163 <[email protected]> * feat: code optimize * feat: code optimize Co-authored-by: tangwenhui <[email protected]> Co-authored-by: afc163 <[email protected]>
1 parent 55f6571 commit 3e0214f

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

src/hooks/usePickerInput.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)