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: 修复 calendar-picker-view 的一些问题 #6760

Merged
merged 7 commits into from
Oct 17, 2024

Conversation

yuanjiu041
Copy link
Contributor

const maxDay = useMemo(
() => (props.max ? dayjs(props.max) : current.add(6, 'month')),
[props.max, current]
() => (props.max ? dayjs(props.max) : defaultMin.add(6, 'month')),
Copy link
Member

Choose a reason for hiding this comment

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

Test case?

Copy link

codecov bot commented Oct 15, 2024

Codecov Report

Attention: Patch coverage is 86.95652% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.74%. Comparing base (b805b5a) to head (713da41).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ents/calendar-picker-view/calendar-picker-view.tsx 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6760      +/-   ##
==========================================
+ Coverage   92.68%   92.74%   +0.05%     
==========================================
  Files         334      334              
  Lines        7191     7204      +13     
  Branches     1795     1763      -32     
==========================================
+ Hits         6665     6681      +16     
+ Misses        517      515       -2     
+ Partials        9        8       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -124,20 +128,23 @@ export const CalendarPickerView = forwardRef<
const scrollTo = useSyncScroll(current, context.visible, bodyRef)

// ============================== Boundary ==============================
// 记录默认的 current,防止后续 current 更新影响到下面的 minDay 和 maxDay 的计算
const defaultMin = useMemo(() => current, [])
Copy link
Member

Choose a reason for hiding this comment

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

这个有点怪,如果不设置 min 的时候,defaultMin 锁死是当前日期。至少也是这个月的开始才对?如果留有余量的话,应该是范围默认正负半年比较好

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
Contributor Author

Choose a reason for hiding this comment

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

current 取值的时候,默认会选到第一天,所以这个 defaultMin 依赖的 moment 本来就是 x月1号
image
这里 defaultMin 的操作就是在原来 current 的基础上,保证他不随后续 current 的变化而变化,其他逻辑没变

Copy link
Member

Choose a reason for hiding this comment

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

OK,那如果 current 受控小于当前日期呢?是不是需要刷新一下~

)

// ================================ Refs ================================
useImperativeHandle(ref, () => ({
jumpTo: pageOrPageGenerator => {
let page: Page
if (typeof pageOrPageGenerator === 'function') {
console.log('cccc: ', current)
Copy link
Member

Choose a reason for hiding this comment

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

console 没删

@zombieJ zombieJ merged commit 763125e into ant-design:master Oct 17, 2024
9 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.

2 participants