-
-
Notifications
You must be signed in to change notification settings - Fork 319
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
fix: interacting with footer components closes the date selection panel #683
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ export default function usePickerInput({ | |
onKeyDown, | ||
blurToCancel, | ||
changeOnBlur, | ||
hasExtraFooter, | ||
onSubmit, | ||
onCancel, | ||
onFocus, | ||
|
@@ -25,14 +26,16 @@ export default function usePickerInput({ | |
forwardKeyDown: (e: React.KeyboardEvent<HTMLInputElement>) => boolean; | ||
onKeyDown: (e: React.KeyboardEvent<HTMLInputElement>, preventDefault: () => void) => void; | ||
blurToCancel?: boolean; | ||
changeOnBlur?: boolean | ||
changeOnBlur?: boolean; | ||
hasExtraFooter?: boolean; | ||
onSubmit: () => void | boolean; | ||
onCancel: () => void; | ||
onFocus?: React.FocusEventHandler<HTMLInputElement>; | ||
onBlur?: React.FocusEventHandler<HTMLInputElement>; | ||
}): [React.DOMAttributes<HTMLInputElement>, { focused: boolean; typing: boolean }] { | ||
const [typing, setTyping] = useState(false); | ||
const [focused, setFocused] = useState(false); | ||
const [outside, setOutside] = useState(true); | ||
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. 这个改变需要 render 吗,可以用 useRef 吗 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. 对,只需要阻塞一下 blur。 |
||
|
||
/** | ||
* We will prevent blur to handle open event when user click outside, | ||
|
@@ -108,7 +111,7 @@ export default function usePickerInput({ | |
}, | ||
|
||
onBlur: (e) => { | ||
if (preventBlurRef.current || !isClickOutside(document.activeElement)) { | ||
if (preventBlurRef.current || !isClickOutside(document.activeElement) || !outside) { | ||
preventBlurRef.current = false; | ||
return; | ||
} | ||
|
@@ -152,6 +155,11 @@ export default function usePickerInput({ | |
const target = getTargetFromEvent(e); | ||
const clickedOutside = isClickOutside(target); | ||
|
||
if (hasExtraFooter) { | ||
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. 这种零碎逻辑太多了不好,感觉是写个 RFC 让 ConfigProvider 支持关闭逻辑。例如默认是 blur 关闭,也可以设置成点击外部关闭。这样就不管你是哪个组件,都是一样的逻辑。 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. 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. 另外,点击 renderExtraFooter 位置元素,应该不属于 blur 啊?也没有离开 Picker 啊?为什么会触发 blur 呢? 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. 触发了 input 的 blur 。 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. 还有 Select 的自定义 render,也需要阻止冒泡。按理说点击自定义添加的按钮或者 Input,应该不属于 Select 的选中,不应该关闭 Select 的下拉框的 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. 对的,所以这里可以整理一个 RFC 出来。 |
||
// Save whether the last click is inside the component when `extraFooter` exists. | ||
setOutside(clickedOutside); | ||
} | ||
|
||
if (open) { | ||
if (!clickedOutside) { | ||
preventBlurRef.current = true; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usePickerInput 可以直接接收 renderExtraFooter 吗,不需要用 hasExtraFooter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
里面主要用来做逻辑判断应该用不到 renderExtraFooter 方法,因此我在外面判断是否存在。