Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/hooks/usePickerInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default function usePickerInput({
onFocus?: React.FocusEventHandler<HTMLInputElement>;
onBlur?: React.FocusEventHandler<HTMLInputElement>;
currentFocusedKey?: React.MutableRefObject<string>;
key: string;
key?: string;
}): [React.DOMAttributes<HTMLInputElement>, { focused: boolean; typing: boolean }] {
const [typing, setTyping] = useState(false);
const [focused, setFocused] = useState(false);
Expand Down Expand Up @@ -104,7 +104,9 @@ export default function usePickerInput({
setTyping(true);
setFocused(true);

currentFocusedKey.current = key;
if (currentFocusedKey) {
currentFocusedKey.current = key;
}
clearTimeout(delayBlurTimer.current);
if (onFocus) {
onFocus(e);
Expand Down Expand Up @@ -136,16 +138,19 @@ export default function usePickerInput({
}
}
setFocused(false);

currentFocusedKey.current = '';
// Delay to prevent 'range' focus transitions from firing resulting in incorrect out-of-focus events
delayBlurTimer.current = setTimeout(() => {
// Prevent the 'blur' event from firing when there is currently a focused input
if (currentFocusedKey.current) return;
if (onBlur) {
onBlur(e);
}
}, 100);
if (currentFocusedKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentFocusedKey 有可能不存在么?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

目前只有测试用例中可能不传,我们需要给所有的测试用例都加上吗?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以真实情况为主吧,不要为了测试用例改代码。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果不是范围选择框,而是单个的时间选择器的时候,我们也不需要穿currentFocusedKey.
image
所以实际上只有范围选择器因为有多个输入框,才需要传入这个

currentFocusedKey.current = '';
// Delay to prevent 'range' focus transitions from firing resulting in incorrect out-of-focus events
delayBlurTimer.current = setTimeout(() => {
// Prevent the 'blur' event from firing when there is currently a focused input
if (currentFocusedKey.current) {
return;
}
onBlur?.(e);
}, 100);
} else {
onBlur?.(e);
}
},
};

Expand Down