-
-
Notifications
You must be signed in to change notification settings - Fork 334
fix: key should be a optional param #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
acc7ed4
e3c73a4
e539e00
ad9a5d8
675de79
f1b893f
905ae21
e6625eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
|
@@ -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); | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. currentFocusedKey 有可能不存在么? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前只有测试用例中可能不传,我们需要给所有的测试用例都加上吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 以真实情况为主吧,不要为了测试用例改代码。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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); | ||
} | ||
}, | ||
}; | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.