Skip to content

fix: support manual input clearing - #1006

Open
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/manual-clear-input
Open

fix: support manual input clearing#1006
nrps9909 wants to merge 1 commit into
react-component:masterfrom
nrps9909:codex/manual-clear-input

Conversation

@nrps9909

@nrps9909 nrps9909 commented Aug 27, 2026

Copy link
Copy Markdown

Summary

  • treat an empty input as a clear action only when the picker is clearable, including mask-formatted inputs
  • make SinglePicker manual clearing follow the existing clear path
  • clear a whole RangePicker by default, while preserving the opposite value when the cleared field explicitly allows empty
  • keep the previous reset behavior when allowClear={false}

Closes #946.
Related to ant-design/ant-design#52473. This is a current-master alternative to the conflicting #827 and #947; it also covers the RangePicker behavior requested in the latter review.

Validation

  • rc-test --runInBand --silent: 15 suites, 472 passed, 2 skipped, 29 snapshots
  • focused Picker and RangePicker suites: 236 passed, 2 skipped
  • tsc --noEmit
  • npm run compile
  • ESLint: 0 errors (16 pre-existing hook warnings on current master)
  • Prettier and git diff --check

Causal check: temporarily disabling the empty-text-to-clear propagation made all three new clearing-contract tests fail with zero onChange calls; restoring it made them pass.

AI assistance disclosure: Codex was used to trace the current input/range state flow, compare the stale PRs, draft the implementation and tests, and run the validation matrix. The behavior and causal reversal were verified locally on exact master 16084b6a1593d8815a6ae65cba4e6f7ce8d48c9a.

Summary by CodeRabbit

  • 新功能

    • 支持清空单日期和日期范围选择器的输入值。
    • 清空时可根据配置保留范围中的部分日期。
    • 清空操作会正确触发变更与清除回调,并关闭选择面板。
  • 问题修复

    • 修复可清除选择器无法正确处理空输入的问题。
    • 禁用清除功能时,清空并失焦不会错误地提交变更。

@vercel

vercel Bot commented Aug 27, 2026

Copy link
Copy Markdown

@nrps9909 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 Aug 27, 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: Pro Plus

Run ID: ce65c345-7349-46e9-b76c-c18ad451d641

📥 Commits

Reviewing files that changed from the base of the PR and between 16084b6 and d5a11ea.

📒 Files selected for processing (7)
  • src/PickerInput/RangePicker.tsx
  • src/PickerInput/Selector/Input.tsx
  • src/PickerInput/Selector/RangeSelector.tsx
  • src/PickerInput/Selector/SingleSelector/index.tsx
  • src/PickerInput/Selector/hooks/useInputProps.ts
  • tests/picker.spec.tsx
  • tests/range.spec.tsx

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


Walkthrough

本次修改支持通过删除输入文本清空单值和范围值。可清除输入会传递 null,单值选择器触发清除,范围选择器根据 allowEmpty 保留部分值或清空整个范围。

Changes

手动清空选择值

Layer / File(s) Summary
输入清空处理
src/PickerInput/Selector/Input.tsx, src/PickerInput/Selector/hooks/useInputProps.ts
新增 clearable 属性。可清除选择器收到空文本时,直接清空输入并调用 onChange(null, index),不再进入无效格式处理。
选择器清空传递
src/PickerInput/Selector/RangeSelector.tsx, src/PickerInput/Selector/SingleSelector/index.tsx, src/PickerInput/RangePicker.tsx
允许选择器接收 null。单值选择器触发清除。范围选择器根据 allowEmpty 更新部分范围或整体清空,并关闭弹窗。
清空行为验证
tests/picker.spec.tsx, tests/range.spec.tsx
新增单值和范围清空测试,并验证 allowClear={false} 仍保留原值。

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

Merge Risk: ⚪ Minimal · up to d5a11

This PR adds manual clearing for clearable picker inputs while preserving existing behavior when clearing is disabled and applying the documented range rules. No actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: zombiej, qdyanbing, afc163

Poem

小兔删去日期线,
空值跳入选择间。
单值清除门扉闭,
范围留下一端眠。
测试守住新行为,
胡萝卜庆祝今天。

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 7 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 标题“fix: support manual input clearing”简洁且准确地概括了手动清空选择器输入的主要变更。
Linked Issues check ✅ Passed PR 实现了 #946 的核心要求:可清除选择器在手动清空输入时触发 onChange(null),保持输入为空并清除选择值。实现覆盖单值和范围选择器,并保留 allowClear={false} 的原有行为。测试还覆盖了范围选择器的 allowEmpty 部分清空逻辑。
Out of Scope Changes check ✅ Passed 所有代码变更都围绕手动清空选择器输入、单值与范围清除逻辑、allowEmpty 行为及对应测试展开。未发现与关联问题无关的代码变更。
  • 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.

DatePicker does not trigger onChange when manually clearing input text

1 participant