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

disableDate后导致部分日期无法禁用或无法点击 #188

Closed
wants to merge 7 commits into from
Closed

Conversation

HelloAny
Copy link

1、禁用日期后decade无法禁用

具体例子见
ant-design #28155

2、在disableDate今日日期后选择’年份‘或’月份‘无法返回

ant-design #28155中我发现了新问题,在禁用当年的时间后点击年或月无法返回

更新日志

  • 更改DisableDate参数数值
  • 修改DecadePanel的Disable方式

1.Cannot select Year or Month when disabled the date.
2.The choice decade presents the problem of showing the wrong decade
@vercel
Copy link

vercel bot commented Dec 10, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/react-component/picker/kx1f4skop
✅ Preview: https://picker-git-master.react-component.now.sh

@codecov
Copy link

codecov bot commented Dec 10, 2020

Codecov Report

Merging #188 (2d1272c) into master (bf3ef16) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #188   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          45       45           
  Lines        2033     2045   +12     
  Branches      600      599    -1     
=======================================
+ Hits         2025     2037   +12     
  Misses          6        6           
  Partials        2        2           
Impacted Files Coverage Δ
src/PickerPanel.tsx 100.00% <ø> (ø)
src/panels/DatePanel/DateBody.tsx 96.00% <ø> (ø)
src/panels/MonthPanel/MonthBody.tsx 91.30% <ø> (ø)
src/panels/YearPanel/YearBody.tsx 100.00% <ø> (ø)
src/generate/dateFns.ts 100.00% <100.00%> (ø)
src/generate/dayjs.ts 100.00% <100.00%> (ø)
src/generate/moment.ts 100.00% <100.00%> (ø)
src/panels/DecadePanel/DecadeBody.tsx 100.00% <100.00%> (ø)
src/panels/PanelBody.tsx 100.00% <100.00%> (ø)
src/panels/QuarterPanel/QuarterBody.tsx 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bf3ef16...2d1272c. Read the comment docs.

@HelloAny
Copy link
Author

此外 ant-design #26697也是这样的问题

@@ -62,6 +63,8 @@ const generateConfig: GenerateConfig<Date> = {
setHour: (date, hour) => setHours(date, hour),
setMinute: (date, minute) => setMinutes(date, minute),
setSecond: (date, second) => setSeconds(date, second),
addEndMonth: (date, diff) => addMonths(endOfMonth(date), diff),
addEndYear: (date, diff) => addYears(endOfYear(date), diff),
Copy link
Member

Choose a reason for hiding this comment

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

这个里面的方法都是到时暴露给用户的,但是在这里只是供内部使用,不够优雅。

我认为这个应该是判断禁用时的边界问题,看看能不能通过内部写个自定义的hook什么的专门判断月份、年等面板的禁用日期?

Copy link
Author

Choose a reason for hiding this comment

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

在判断月份和年等面板的时候是用户的disableDate函数返回,这个函数内部对比是无法感知的而且是基于moment等外部库的比较,如果用内部的自定义方法去干涉disableDate函数内部的比较可能会导致antd暴露的api产生变动。

关于generate里的方法似乎只是内部使用,我并未找到暴露的接口😂

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
Author

Choose a reason for hiding this comment

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

没事😅,其他能帮忙review一下吗

Copy link
Member

Choose a reason for hiding this comment

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

你这个解决方案是将调用 disableDate 函数的日期参数改为了,月、年、十年的末尾日期去比较,这样的确解决了 issue 里面的问题,但是应该没有从根源解决。

issue 中 disableDate 的逻辑是禁用今天与今天之前的日期,用你这种方法是可行的,但是如果 disableDate 禁用的是今天和今天之后的日期,这是切换到月份面板的时候,按照你的方法,当前的月份还是会被禁用的,还有更复杂的,当禁用这个月中的某个区间的时候(例如今天19号,禁用15号到20号),你的方法还是不适用的。

Copy link
Author

Choose a reason for hiding this comment

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

感觉只有重写disable逻辑才能解决问题了,因为这一步是将内部的函数暴露给用户,用户的逻辑代码无法获取

@kerm1it
Copy link
Member

kerm1it commented Dec 19, 2020

我重写了 disabledDate 的逻辑,可以去这里看看,帮忙测测有什么问题:#191

@kerm1it
Copy link
Member

kerm1it commented Dec 19, 2020

这个我就先关了,所有问题可以在那边讨论,到时提交的时候,作者我会把你加上的。

@kerm1it kerm1it closed this Dec 19, 2020
@HelloAny
Copy link
Author

这个我就先关了,所有问题可以在那边讨论,到时提交的时候,作者我会把你加上的。

好的,谢谢带佬😘

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