Skip to content

fix: use current time in time picker disabledTime - #1011

Open
dogledogle wants to merge 1 commit into
react-component:masterfrom
dogledogle:fix/time-picker-disabled-time-now
Open

fix: use current time in time picker disabledTime#1011
dogledogle wants to merge 1 commit into
react-component:masterfrom
dogledogle:fix/time-picker-disabled-time-now

Conversation

@dogledogle

@dogledogle dogledogle commented Sep 3, 2026

Copy link
Copy Markdown

Fix ant-design/ant-design#48276

Problem

For a pure time picker, disabledTime receives the panel's draft value after an hour is selected instead of the current time.

This can cause the selected hour to become disabled or disappear when hideDisabledOptions is enabled.

Solution

Use generateConfig.getNow() when invoking disabledTime for pure time pickers in both SinglePicker and RangePicker, including value validation.

DatePicker with showTime continues to receive the selected date so date-dependent rules are preserved.

Summary by CodeRabbit

  • Bug Fixes
    • 修复时间选择器中禁用时间判断使用选中日期的问题,现改为基于当前时间计算。
    • 时间范围选择器的禁用时间行为同步更新。
    • 日期选择器搭配时间选择时,仍基于所选日期进行禁用时间判断。
    • 优化未配置时间选择选项时的弹出面板处理。

@vercel

vercel Bot commented Sep 3, 2026

Copy link
Copy Markdown

@dogledogle is attempting to deploy a commit to the afc163's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: f2a39f75-d204-4a26-aacb-055a61542a5d

📥 Commits

Reviewing files that changed from the base of the PR and between f367642 and d7bb8fb.

📒 Files selected for processing (4)
  • src/PickerInput/RangePicker.tsx
  • src/PickerInput/SinglePicker.tsx
  • src/PickerInput/hooks/useInvalidate.ts
  • tests/disabledTime.spec.tsx

Included review availability: Your plan provides up to 2 included reviews per hour; 1 remains after this review.


Walkthrough

Changes

时间选择器 disabledTime 行为

Layer / File(s) Summary
时间模式目标日期处理
src/PickerInput/SinglePicker.tsx, src/PickerInput/hooks/useInvalidate.ts
时间模式使用 generateConfig.getNow() 调用 disabledTime。日期模式继续使用传入日期。Popup 使用处理后的 mergedShowTime
范围时间选择器目标日期处理
src/PickerInput/RangePicker.tsx
时间模式的 proxyDisabledTime 使用当前时间。其他模式继续使用选中日期。
disabledTime 行为验证
tests/disabledTime.spec.tsx
新增测试,验证 TimePicker 和 TimeRangePicker 使用当前时间,DatePicker 使用选中日期。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d7bb8

Pure time pickers now evaluate disabled times against the current time after selection, while date pickers with time retain date-dependent behavior. The change is covered across single, range, and validation paths with no active merge risk identified.

Suggested reviewers: zombiej, qdyanbing

Sequence Diagram(s)

sequenceDiagram
  participant TimePicker
  participant SinglePicker
  participant generateConfig
  participant disabledTime
  TimePicker->>SinglePicker: 传入 showTime.disabledTime
  SinglePicker->>generateConfig: getNow()
  generateConfig-->>SinglePicker: 当前时间
  SinglePicker->>disabledTime: 使用当前时间执行校验
  disabledTime-->>TimePicker: 返回禁用时间配置
Loading

Poem

小兔捧着时间盘,
当前时刻不走散。
选中日期仍照旧,
禁用小时排成串。
单选范围都校准,
测试轻轻点头看。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed 标题准确概括了主要变更:在纯时间选择器中使用当前时间处理 disabledTime。
Linked Issues check ✅ Passed 变更满足问题 #48276 的要求。TimePicker 和 TimeRangePicker 在 picker 为 time 时使用 generateConfig.getNow() 调用 disabledTime,并保留 DatePicker showTime 使用选中日期的行为。新增测试覆盖这些场景。
Out of Scope Changes check ✅ Passed 所有代码和测试变更都围绕 disabledTime 在时间选择器中的当前时间语义。未发现与关联问题无关的变更。
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

TimePicker.RangePicker disabledTime "now" does not always contain the current time.

1 participant