generated from react-component/footer
-
-
Notifications
You must be signed in to change notification settings - Fork 331
fix: fix panel not switch when select date with open is true #663
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,10 @@ export default function useRangeOpen( | |
] { | ||
const [firstTimeOpen, setFirstTimeOpen] = React.useState(false); | ||
|
||
const [afferentOpen, setAfferentOpen] = useMergedState(defaultOpen || false, { | ||
value: open, | ||
}); | ||
|
||
const [mergedOpen, setMergedOpen] = useMergedState(defaultOpen || false, { | ||
value: open, | ||
onChange: (nextOpen) => { | ||
|
@@ -62,6 +66,8 @@ export default function useRangeOpen( | |
} | ||
}, [mergedOpen]); | ||
|
||
const queryNextIndex = (index: number) => (index === 0 ? 1 : 0); | ||
|
||
const triggerOpen = useEvent((nextOpen: boolean, index: 0 | 1 | false, source: SourceType) => { | ||
if (index === false) { | ||
// Only when `nextOpen` is false and no need open to next index | ||
|
@@ -70,7 +76,7 @@ export default function useRangeOpen( | |
setMergedActivePickerIndex(index); | ||
setMergedOpen(nextOpen); | ||
|
||
const nextIndex = index === 0 ? 1 : 0; | ||
const nextIndex = queryNextIndex(index); | ||
|
||
// Record next open index | ||
if ( | ||
|
@@ -87,23 +93,27 @@ export default function useRangeOpen( | |
} | ||
} | ||
} else if (source === 'confirm' || (source === 'blur' && changeOnBlur)) { | ||
if (nextActiveIndex !== null) { | ||
const customNextActiveIndex = afferentOpen ? queryNextIndex(index) : nextActiveIndex; | ||
zombieJ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (customNextActiveIndex !== null) { | ||
setFirstTimeOpen(false); | ||
setMergedActivePickerIndex(nextActiveIndex); | ||
setMergedActivePickerIndex(customNextActiveIndex); | ||
} | ||
|
||
setNextActiveIndex(null); | ||
|
||
// Focus back | ||
if (nextActiveIndex !== null && !disabled[nextActiveIndex]) { | ||
if (customNextActiveIndex !== null && !disabled[customNextActiveIndex]) { | ||
raf(() => { | ||
const ref = [startInputRef, endInputRef][nextActiveIndex]; | ||
const ref = [startInputRef, endInputRef][customNextActiveIndex]; | ||
ref.current?.focus(); | ||
}); | ||
} else { | ||
setMergedOpen(false); | ||
} | ||
} else { | ||
setMergedOpen(false); | ||
setAfferentOpen(false); | ||
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. 对,受控关闭的话是不会走到这里,这里是考虑到在 defaultOpen 为 true 的情况下,选择完日期点击外部内容触发关闭后会走到这里,如果不设置为 false 的话后续 defaultOpen 因为会一直为 true,此时的状态应该是不对的。 |
||
} | ||
}); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
你没发现这样子就和下面 mergedOpen 一样了么 😄
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.
对的,这里我想让 defaultOpen 首次参与 open 的计算,后续不会影响到 afferentOpen 这个值,跟 mergedOpen 不同的是 只有一处主动调用了 set 方法,后续状态变更时我这边测出来 afferentOpen 的值和 mergedOpen 的值是不一致的 😂