Skip to content
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: fix panel not switch when select date with open is true #663

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

Yuiai01
Copy link
Contributor

@Yuiai01 Yuiai01 commented Aug 3, 2023

@vercel
Copy link

vercel bot commented Aug 3, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
picker ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 4, 2023 3:23am

@codecov
Copy link

codecov bot commented Aug 3, 2023

Codecov Report

Merging #663 (d17685b) into master (a67d2a0) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head d17685b differs from pull request most recent head 5500cd3. Consider uploading reports for the commit 5500cd3 to get more accurate results

@@           Coverage Diff           @@
##           master     #663   +/-   ##
=======================================
  Coverage   99.05%   99.05%           
=======================================
  Files          56       56           
  Lines        2426     2430    +4     
  Branches      720      734   +14     
=======================================
+ Hits         2403     2407    +4     
  Misses         21       21           
  Partials        2        2           
Files Changed Coverage Δ
src/hooks/useRangeOpen.ts 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@zombieJ
Copy link
Member

zombieJ commented Aug 3, 2023

这个说明一下思路?

@Yuiai01
Copy link
Contributor Author

Yuiai01 commented Aug 3, 2023

这个说明一下思路?

好,当前如果 open、defaultOpen 为 true 时,时间选择面板默认是打开的,相较于点击输入框打开时间选择面板缺少了设置 nextActiveIndex 这个值的过程,因此这个值一直为 null 走不进正确的流程,导致我们选择时间后也不会切换面板。
我的解决思路就是:
1、当 open、defaultOpen 其中一个值为 true 时,代表当前面板是打开状态,所以跳过了 nextActiveIndex 的校验,
2、当点击选择时间后需要切换到另一个面板,因此在这里设置了 mergedActivePickerIndex 的值为下一个面板的 index 来进行切换。

@@ -43,6 +43,10 @@ export default function useRangeOpen(
] {
const [firstTimeOpen, setFirstTimeOpen] = React.useState(false);

const [afferentOpen, setAfferentOpen] = useMergedState(defaultOpen || false, {
Copy link
Member

Choose a reason for hiding this comment

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

你没发现这样子就和下面 mergedOpen 一样了么 😄

Copy link
Contributor Author

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 的值是不一致的 😂

ref.current?.focus();
});
} else {
setMergedOpen(false);
}
} else {
setMergedOpen(false);
setAfferentOpen(false);
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.

对,受控关闭的话是不会走到这里,这里是考虑到在 defaultOpen 为 true 的情况下,选择完日期点击外部内容触发关闭后会走到这里,如果不设置为 false 的话后续 defaultOpen 因为会一直为 true,此时的状态应该是不对的。

@zombieJ zombieJ merged commit 1d13a31 into react-component:master Aug 8, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RangePicker is not working properly while picker in default open state
2 participants