Support onClear callback in picker#976
Conversation
|
@QDyanbing is attempting to deploy a commit to the React Component Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 16 minutes and 30 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
Walkthrough为 Picker 组件新增 onClear 回调属性。通过接口定义、两个选择器实现、属性透传控制、测试用例和文档说明的完整流程,支持在清除操作时触发用户自定义的回调函数。 ChangesonClear 回调特性
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces an onClear callback prop to both single and range pickers, which is triggered when the clear button is clicked, and includes corresponding unit tests and documentation. The reviewer pointed out that onClear is destructured but not omitted from panelProps in both RangePicker.tsx and SinglePicker.tsx. This omission could cause the prop to be passed down to the Popup component, potentially triggering React unrecognized prop warnings in the console. It is recommended to add 'onClear' to the omit list in both files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
670ac71 to
b9d7286
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #976 +/- ##
=======================================
Coverage 98.81% 98.81%
=======================================
Files 66 66
Lines 2696 2698 +2
Branches 744 744
=======================================
+ Hits 2664 2666 +2
Misses 29 29
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
b9d7286 to
32a7bef
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
tests/picker.spec.tsx (1)
948-956: ⚡ Quick win建议显式验证
onClear回调不接收任何参数。当前测试仅检查了调用次数(
toHaveBeenCalledTimes(1)),但根据 PR 描述和类型定义,onClear应为VoidFunction(无参数回调)。建议添加显式断言以验证回调签名:clearValue(); expect(onClear).toHaveBeenCalledTimes(1); + expect(onClear).toHaveBeenCalledWith(); expect(document.querySelector('input').value).toEqual('');这样可以确保 API 契约得到遵守,防止未来意外引入参数导致的回归问题。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/picker.spec.tsx` around lines 948 - 956, The test currently only asserts onClear was called once; update the "trigger onClear when clear value" test to also assert that onClear was invoked with no arguments by adding expect(onClear).toHaveBeenCalledWith(); (keep existing render of DayPicker with onClear and the clearValue() call unchanged) so the test verifies the callback is a VoidFunction.tests/range.spec.tsx (1)
1956-1970: ⚡ Quick win建议显式验证
onClear回调不接收任何参数。当前测试仅检查了调用次数(
toHaveBeenCalledTimes(1)),但根据 PR 描述和类型定义,onClear应为VoidFunction(无参数回调)。建议添加显式断言以验证回调签名:clearValue(); expect(onClear).toHaveBeenCalledTimes(1); + expect(onClear).toHaveBeenCalledWith(); expect(document.querySelector('input').value).toEqual('');这样可以确保 API 契约得到遵守,防止未来意外引入参数导致的回归问题。
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/range.spec.tsx` around lines 1956 - 1970, Add an explicit assertion that the onClear mock receives no arguments: after invoking clearValue() and the existing expect(onClear).toHaveBeenCalledTimes(1), add expect(onClear).toHaveBeenCalledWith() (or an equivalent zero-argument assertion) to the test that renders DayRangePicker with allowClear; reference the onClear mock, the DayRangePicker render, and the clearValue() helper so the test verifies the callback is a VoidFunction.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@README.md`:
- Line 54: 在 README 文档的 API 表中将 onClear 的类型从泛用 Function 明确为无参回调 (VoidFunction 或
() => void) 并在 RangePicker 的 API 表里新增一行同样声明 onClear: VoidFunction/() =>
void;在文中定位到 Picker 表格中对 onClear 的条目(标识符 onClear)替换类型文本,并在 RangePicker 表格(标识符
RangePicker)新增对应行,确保两处文档一致以免用户使用错误签名。
---
Nitpick comments:
In `@tests/picker.spec.tsx`:
- Around line 948-956: The test currently only asserts onClear was called once;
update the "trigger onClear when clear value" test to also assert that onClear
was invoked with no arguments by adding expect(onClear).toHaveBeenCalledWith();
(keep existing render of DayPicker with onClear and the clearValue() call
unchanged) so the test verifies the callback is a VoidFunction.
In `@tests/range.spec.tsx`:
- Around line 1956-1970: Add an explicit assertion that the onClear mock
receives no arguments: after invoking clearValue() and the existing
expect(onClear).toHaveBeenCalledTimes(1), add
expect(onClear).toHaveBeenCalledWith() (or an equivalent zero-argument
assertion) to the test that renders DayRangePicker with allowClear; reference
the onClear mock, the DayRangePicker render, and the clearValue() helper so the
test verifies the callback is a VoidFunction.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1ec3ead7-297f-4e89-9d4f-d748cd24ea67
📒 Files selected for processing (6)
README.mdsrc/PickerInput/RangePicker.tsxsrc/PickerInput/SinglePicker.tsxsrc/interface.tsxtests/picker.spec.tsxtests/range.spec.tsx
32a7bef to
0ad2956
Compare
变更内容
onClear回调类型。onClear,并保持现有清空与关闭弹层逻辑不变。背景
Ant Design 反馈 DatePicker / TimePicker 等支持清空的输入组件缺少清空回调。rc-picker 已有内部清空链路,但没有向外暴露对应 API。本次实现对齐 rc-input、rc-select 等组件的无参
onClear设计。关联 ant-design/ant-design#58349。
验证
npm run lint:tscnpm test -- --runTestsByPath tests/range.spec.tsxnpm test -- --runTestsByPath tests/picker.spec.tsxnpm run lint无 error,仅有项目既有 warninggit diff --checkSummary by CodeRabbit
发布说明
新增功能
onClear回调属性,在清除已选值时自动触发执行。文档
onClear属性的详细说明。测试
onClear回调功能的测试用例。