Skip to content

Conversation

@alii13
Copy link

@alii13 alii13 commented Oct 27, 2025

Title

fix: trigger onChange when manually clearing input via select all + delete

Description

This PR fixes the issue where manually clearing a date input by selecting all text (Ctrl+A/Cmd+A) and pressing Delete/Backspace does not trigger the onChange callback.

Problem

When users manually select and delete date text in the input field:

  • onChange was NOT triggered
  • ❌ After blur, the previous date value reappeared
  • ❌ Inconsistent with the clear button (×) behavior

This was a UX and accessibility issue that prevented keyboard-only users from clearing dates effectively.

Solution

Changes Made:

  1. useInputProps.ts - Added logic to detect empty input and trigger onChange(null)
  2. Input.tsx - Added handlers for both formatted and non-formatted inputs
  3. SingleSelector/index.tsx - Updated to properly handle null values
  4. manual-clear.spec.tsx - Added 11 comprehensive tests

Behavior After Fix:

  • ✅ Select all text (Ctrl+A/Cmd+A) and press Delete → input clears immediately
  • onChange is called with (null, null)
  • ✅ Matches clear button behavior exactly
  • ✅ Works for both Picker and RangePicker
  • ✅ Works for all picker modes (date, week, month, year, quarter, time)

Testing

All Tests Pass

  • 453 existing tests pass ✅ (no breaking changes)
  • 11 new tests added ✅ (comprehensive coverage)
  • Total: 16 test suites, 455 tests

Manual Testing

  1. Click in the input
  2. Select all text: Ctrl+A (Windows/Linux) or Cmd+A (Mac)
  3. Press Delete or Backspace
  4. Verify input clears and onChange is triggered

Backward Compatibility

Fully backward compatible - all existing tests pass

  • Invalid partial inputs still reset on blur (existing behavior preserved)
  • Clear button behavior unchanged
  • No API changes

Fixes

Fixes ant-design/ant-design#52473

Summary by CodeRabbit

  • Bug Fixes

    • 改进了日期/区间选择器的手动清除与空输入处理:在输入清空或通过清除控件时会显式走清除路径、重置输入并同步外部状态;单选场景在为空且允许清除时会触发清除回调;公共 API 保持不变。
  • Tests

    • 新增全面手动清除测试,覆盖通过输入/失焦与清除控件、allowClear 不同配置、无效部分输入、不同行为模式与掩码、范围起止清空等场景,提升一致性验证。

…elete

When users manually select all text (Ctrl+A) and press Delete/Backspace,
the onChange callback is now properly triggered with null, matching the
behavior of the clear button.

Previously, the input would reset to the previous value on blur without
triggering onChange, which was inconsistent and prevented users from
clearing dates via keyboard.

Changes:
- Modified useInputProps to detect empty input and trigger onChange(null)
- Added handlers in Input component for both formatted and non-formatted inputs
- Updated SingleSelector to properly handle null values by calling onClear
- Added comprehensive test coverage with 11 new tests

Fixes: #52473 (ant-design/ant-design)

All existing tests pass (453 tests), ensuring backward compatibility.
@vercel
Copy link

vercel bot commented Oct 27, 2025

@alii13 is attempting to deploy a commit to the React Component Team on Vercel.

A member of the Team first needs to authorize it.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @alii13, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a significant user experience and accessibility flaw in date input components. Previously, manually clearing a date field by selecting all text and pressing delete or backspace would not correctly trigger the onChange event, leading to inconsistent state and the reappearance of old values. The implemented solution ensures that such manual clearing actions are properly recognized, triggering onChange(null) and providing a consistent, accessible experience across all picker types and modes, mirroring the behavior of the dedicated clear button.

Highlights

  • Manual Clear Fix: Implemented a fix to ensure the onChange callback is triggered when a date input is manually cleared using "select all + delete/backspace".
  • Consistent Behavior: The manual clearing behavior now aligns with the dedicated clear button, preventing previous date values from reappearing on blur.
  • Enhanced Accessibility: This change improves keyboard accessibility for users who clear date inputs without relying on a mouse.
  • Broad Coverage: The fix applies consistently to both single and range pickers, and across all picker modes (date, week, month, year, quarter, time).
  • Comprehensive Testing: 11 new, comprehensive tests have been added to validate the new functionality across various scenarios, ensuring robustness.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

在输入与选择处理路径中加入对手动清空的显式处理:当输入变为空或通过键盘(全选 + Backspace/Delete)清除时,触发相应的清空回调(onChange(null)/onClear),更新输入状态并提前返回以阻止后续处理。

Changes

Cohort / File(s) 变更摘要
输入组件改动
src/PickerInput/Selector/Input.tsx
提取顶部输入文本变量并在通用/无格式化路径中检测并处理手动清空:当输入变为空且当前值非空且存在清空图标时,调用 onChange('') 并重置输入值,阻止默认事件并提前返回;同时统一使用顶部提取的 text 变量以避免重复声明。
单选选择器
src/PickerInput/Selector/SingleSelector/index.tsx
将单选变更处理改为接受 `DateType
输入属性钩子
src/PickerInput/Selector/hooks/useInputProps.ts
增加空字符串分支:当 text === '' 时先调用 onInvalid(false, index)onChange(null, index) 并提前返回,确保外部状态与无效标记同步并阻止后续验证流程。
测试
tests/manual-clear.spec.tsx
新增手动清空相关测试,覆盖键盘/输入/blur 清空、allowClear 开关、range picker 两端清空、不同模式与掩码下行为,使用 dayjs generateConfig、en_US locale 与假定定时器模拟异步验证。

Sequence Diagram(s)

sequenceDiagram
    participant 用户
    participant Input as Input 组件
    participant Hook as useInputProps
    participant Selector as SingleSelector
    participant Parent as 上层 onChange/onClear

    Note over 用户,Input: 用户全选并按 Delete/Backspace 或 将输入清空
    用户->>Input: 输入事件 / keydown
    alt 检测到手动清空 (text === '' 且 当前值非空)
        Input->>Input: 阻止默认、重置输入值
        Input->>Parent: onChange(null) / onClear()
        Note right of Parent: 上层接收空值清空事件
    else 常规格式化/校验流程
        Input->>Hook: 继续格式化与校验(可能触发 onModify/onChange)
    end

    Note over Input,Hook: 若 text === '' 导致钩子提前返回
    Input->>Hook: text === ''
    Hook->>Hook: onInvalid(false), onChange(null) 并提前返回
    Hook-->>Parent: onChange(null)

    Note over Selector: 通过选择器接口触发选择/清空
    用户->>Selector: 选择器产生 date (可能为 null)
    alt date === null
        Selector->>Parent: onClear()
    else
        Selector->>Parent: onChange([date])
    end
Loading

Estimated code review effort

🎯 3 (中等) | ⏱️ ~20-25 minutes

需要额外关注:

  • src/PickerInput/Selector/Input.tsx 中对选区/光标状态与 preventDefault 的判断是否覆盖所有输入场景(含掩码/格式化路径)。
  • src/PickerInput/Selector/hooks/useInputProps.ts 的空字符串早退对去抖、异步验证和现有校验流程的影响。
  • src/PickerInput/Selector/SingleSelector/index.tsx 中 onClear/onChange 的调用时机与副作用顺序。
  • 新增测试中使用的假定定时器与 locale 设置对 CI 稳定性的影响。

Possibly related issues

Possibly related PRs

Suggested reviewers

  • afc163
  • zombieJ

诗语

🐰 退格轻敲风声短,字符随手散云端,
空白化作 null 一环,onChange 回声暖心间,
测试护航夜半看,清空今朝终可安。

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed 拉取请求标题"fix: trigger onChange when manually clearing input via select all + delete"清晰准确地描述了主要变更。标题具体说明了修复内容(通过选中所有文本后删除来手动清空输入时触发onChange回调),与提供的代码摘要中所有四个修改文件的核心目标保持一致。标题简洁明了,没有冗余信息,能够帮助开发人员快速理解此变更的主要作用。
Linked Issues Check ✅ Passed 本次拉取请求的代码变更完全符合关联问题#52473的所有核心要求。问题要求允许通过选中所有文本并按Delete/Backspace键手动清空日期选择器输入,并确保此行为与清除按钮(×)相同、触发onChange回调、防止模糊焦点后日期重新出现、以及支持所有选择器模式。代码修改(useInputProps.ts中添加空输入检测、Input.tsx中处理已格式化和未格式化输入、SingleSelector/index.tsx中处理null值)和新增的11个全面测试套件直接解决了这些要求。测试覆盖了不同的选择器模式、allowClear配置选项以及手动清除与清除按钮的一致性验证。
Out of Scope Changes Check ✅ Passed 所有代码变更均直接与问题#52473的修复目标相关,不存在超出范围的改动。四个修改文件(Input.tsx、SingleSelector/index.tsx、useInputProps.ts和manual-clear.spec.tsx)的变更都专注于实现手动清空输入功能。新增的测试仅验证手动清除行为及其与清除按钮的一致性,不涉及其他功能或特性的改动。代码摘要明确指出未对导出或公共实体签名进行任何改动,确保了后向兼容性。
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 669467f and 81b32b6.

📒 Files selected for processing (1)
  • tests/manual-clear.spec.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/manual-clear.spec.tsx (1)
tests/util/commonUtil.tsx (3)
  • getDay (186-195)
  • openPicker (78-87)
  • waitFakeTimer (71-76)
🔇 Additional comments (3)
tests/manual-clear.spec.tsx (3)

8-16: 测试设置正确。

使用假计时器固定时间点,并在测试后正确清理,这是测试日期选择器的标准做法。


67-86: 已修复:测试现在正确输入了部分值。

此测试已根据之前的反馈进行了修正。第 80 行现在正确地输入了部分日期值 '2023-08',然后验证在 blur 时该值被重置为完整日期 '2023-08-01' 且不触发 onChange。测试描述与实际行为现在一致。


265-302: 优秀的对比测试!

此测试很好地验证了手动清空和清除按钮行为的一致性。两个 onChange 回调都被正确断言,确保两种清空方式产生相同的结果。这种对比测试对于保证功能等价性非常有价值。


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 and usage tips.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses an issue where the onChange callback was not triggered when manually clearing a date input using select all + delete. The solution involves adding logic to detect empty input and trigger onChange(null), handling null values properly, and adding comprehensive tests. The changes are fully backward compatible and include new tests to ensure comprehensive coverage.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0dadb0a and d5bba8d.

📒 Files selected for processing (4)
  • src/PickerInput/Selector/Input.tsx (2 hunks)
  • src/PickerInput/Selector/SingleSelector/index.tsx (1 hunks)
  • src/PickerInput/Selector/hooks/useInputProps.ts (1 hunks)
  • tests/manual-clear.spec.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/PickerInput/Selector/Input.tsx (1)
tests/util/commonUtil.tsx (1)
  • inputValue (163-165)
tests/manual-clear.spec.tsx (1)
tests/util/commonUtil.tsx (3)
  • getDay (186-195)
  • openPicker (78-87)
  • waitFakeTimer (71-76)
🪛 Biome (2.1.2)
src/PickerInput/Selector/Input.tsx

[error] 284-284: Other switch clauses can erroneously access this declaration.
Wrap the declaration in a block to restrict its access to the switch clause.

The declaration is defined in this switch clause:

Safe fix: Wrap the declaration in a block.

(lint/correctness/noSwitchDeclarations)

🔇 Additional comments (4)
src/PickerInput/Selector/SingleSelector/index.tsx (1)

133-139: 逻辑正确!

null 值的处理非常合理,通过调用 onClear() 而不是 onChange([date]),使手动清除输入的行为与清除按钮保持一致。

src/PickerInput/Selector/hooks/useInputProps.ts (1)

188-192: 空输入处理实现正确!

通过调用 onChange(null, index) 并提前返回,确保空输入被正确传播为 null 值。这与清除按钮的行为保持一致。

src/PickerInput/Selector/Input.tsx (1)

216-231: 清除逻辑实现正确!

对于无格式输入,当用户选中全部内容并按下 Backspace/Delete 时,正确地清除了输入值并阻止了默认行为。这确保了手动清除与清除按钮的行为一致。

tests/manual-clear.spec.tsx (1)

1-307: 测试覆盖全面且结构良好!

测试文件提供了出色的覆盖范围:

  • 单选择器的多种清除场景(Delete、Backspace、输入变更)
  • 范围选择器的开始/结束/双输入清除
  • 与清除按钮行为的对比验证
  • 不同 picker 模式的支持
  • 无效部分输入的失焦行为

测试结构清晰,使用了适当的 fake timers 和异步等待,确保了行为的准确验证。

- Extracted duplicate logic into reusable handleManualClear function
- Added JSDoc comment explaining the function's purpose
- Added inline comment explaining why event.preventDefault() is called
- Improved code maintainability and testability
- Renamed function to follow event handler naming convention
- Added explanatory comment for null date handling
- Clarifies that null dates are delegated to onClear handler
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 88c80f2 and a3d4b3c.

📒 Files selected for processing (2)
  • src/PickerInput/Selector/Input.tsx (2 hunks)
  • src/PickerInput/Selector/SingleSelector/index.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/PickerInput/Selector/Input.tsx
🔇 Additional comments (1)
src/PickerInput/Selector/SingleSelector/index.tsx (1)

156-165: 正确集成了新的清空处理逻辑。

handleSingleChange 传递给 useInputProps 正确地连接了手动清空的处理路径,确保当输入被清空时能够触发 onClear 回调。这个改动与 PR 目标一致,使手动清空行为与点击清空按钮的行为保持一致。

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (0dadb0a) to head (81b32b6).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #947   +/-   ##
=======================================
  Coverage   98.80%   98.81%           
=======================================
  Files          65       65           
  Lines        2680     2691   +11     
  Branches      744      748    +4     
=======================================
+ Hits         2648     2659   +11     
  Misses         29       29           
  Partials        3        3           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

- Added test case for mask format inputs to cover onFormatKeyDown path
- Ensures handleManualClear return statement is covered by tests
- Increases test coverage to 456 tests total
@alii13
Copy link
Author

alii13 commented Oct 28, 2025

@li-jia-nan / @afc163 / @zombieJ Can someone please take a look at this PR whenever you have time. Thank you!

@li-jia-nan
Copy link
Member

@zombieJ Please review this

@alii13
Copy link
Author

alii13 commented Oct 30, 2025

Bumping this up, incase missed it.

@zombieJ
Copy link
Member

zombieJ commented Oct 30, 2025

@gemini-code-assist Pls help to CR agaign.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is a great fix that addresses an important UX and accessibility issue with manually clearing date inputs. The approach of handling empty input strings in useInputProps and delegating to onClear in SingleSelector is clean and ensures consistent behavior with the clear button. The addition of handleManualClear in the Input component centralizes the keyboard handling logic nicely.

The new test suite manual-clear.spec.tsx is very comprehensive and covers a wide range of scenarios for both single and range pickers. I have a few suggestions to make the tests for the RangePicker even more robust by adding assertions for the onChange callback, which is the core of this fix.

Overall, excellent work on this PR!

- Changed approach per reviewer feedback (@zombieJ)
- Detect manual clear in onChange event when input becomes empty
- Only allow manual clear when clearIcon is present (allowClear enabled)
- If allowClear is disabled, input resets to previous valid date
- Works for all input methods (keyboard, paste, voice, etc)
- No keyboard event detection needed - cleaner and more general

Changes:
- Input.tsx: Check clearIcon in onChange to allow/prevent manual clear
- SingleSelector: Delegate to onClear when date is null and clearIcon exists
- useInputProps: Trigger onChange(null) when text becomes empty
- Tests: Updated to use fireEvent.change instead of keyDown
- Added test for allowClear={false} behavior

All 455 tests pass with 100% line coverage on new code
@alii13
Copy link
Author

alii13 commented Oct 31, 2025

@gemini-code-assist can you re-review the PR?

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively resolves the issue of onChange not being triggered when an input is manually cleared. The changes are well-implemented across useInputProps.ts, Input.tsx, and SingleSelector/index.tsx to handle the cleared state correctly by propagating a null value, but only when allowClear is enabled. The solution is robust, maintaining consistency with the existing clear button behavior. The addition of a comprehensive suite of 11 new tests in manual-clear.spec.tsx is excellent, providing strong confidence in the fix and covering various scenarios for both single and range pickers. The code is clean, and the problem and solution are very clearly documented in the pull request description. Great work!

- Renamed tests to accurately reflect what they test
- RangePicker doesn't immediately trigger onChange when clearing individual inputs
  (this is expected behavior due to range validation logic)
- Tests verify input values are cleared, not onChange behavior
- All 11 manual clear tests passing

Before: 'should trigger onChange when manually clearing start input'
After: 'should clear start input value when manually clearing'

This addresses review feedback while clarifying the actual behavior being tested.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
tests/manual-clear.spec.tsx (3)

165-187: 应添加 onChange 断言以验证回调行为。

此测试验证了起始输入被清空后的视觉状态,但缺少对 onChange 回调被正确调用的验证。应添加断言确保 onChange 以正确的参数被调用。

基于先前的评审建议,应添加:

 await waitFakeTimer();

+expect(onChange).toHaveBeenCalledWith([null, getDay('2023-08-15')], ['', '2023-08-15']);
 expect(startInput.value).toBe('');

189-211: 应添加 onChange 断言以验证回调行为。

与起始输入测试类似,此测试应验证 onChange 在结束输入被清空时以正确的参数被调用。

基于先前的评审建议,应添加:

 await waitFakeTimer();

+expect(onChange).toHaveBeenCalledWith([getDay('2023-08-01'), null], ['2023-08-01', '']);
 expect(endInput.value).toBe('');

213-241: 应添加 onChange 断言以验证清空两个输入后的最终状态。

当两个输入都被清空后,应验证最终的 onChange 调用使用 null 作为日期值,因为范围中的两个值现在都为空。

基于先前的评审建议,应在测试末尾添加:

 await waitFakeTimer();

+expect(onChange).toHaveBeenLastCalledWith(null, ['', '']);
 expect(startInput.value).toBe('');
 expect(endInput.value).toBe('');
🧹 Nitpick comments (2)
tests/manual-clear.spec.tsx (2)

243-265: 潜在的测试重复。

此测试与第 165-187 行的测试非常相似,都测试清空 RangePicker 的起始输入。主要区别在于:

  • 此测试没有 needConfirm={false} 属性
  • 此测试没有 fireEvent.blur
  • 此测试包含初始值断言(第 257 行)

建议:

  1. 如果这两个测试旨在验证不同的场景(例如,有/无 needConfirm 或有/无 blur),请更新测试描述以明确区分它们
  2. 或者,如果它们测试相同的行为,考虑合并这些测试或删除其中一个以减少冗余

269-306: 测试设计良好,验证了核心 PR 目标。

此测试有效地验证了手动清空与点击清空按钮的行为一致性,这是 PR 的主要目标之一。测试隔离了两个独立的实例并正确地验证了两者都调用 onChange(null, null)

考虑添加一个类似的测试来比较 RangePicker 的手动清空与清空按钮行为,以确保两种组件的行为一致性。

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 91955bd and 669467f.

📒 Files selected for processing (1)
  • tests/manual-clear.spec.tsx (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
tests/manual-clear.spec.tsx (1)
tests/util/commonUtil.tsx (3)
  • getDay (186-195)
  • openPicker (78-87)
  • waitFakeTimer (71-76)
🔇 Additional comments (2)
tests/manual-clear.spec.tsx (2)

8-16: 测试设置正确。

beforeEach 和 afterEach 的配置合理,使用假计时器来测试异步行为,并在每个测试后正确清理。


1-308: 审查意见包含多项不准确的指控,需要更正。

您的审查意见在以下方面有误:

  1. 无需显式键盘事件测试 - 根据 git 历史,实现使用"onChange detection instead of keyDown",而非直接监听键盘事件。因此 fireEvent.change() 是正确且充分的测试方式,无需额外的键盘事件模拟。

  2. 对比测试已存在 - 虽然对比测试仅覆盖 Picker(第305行附近),但并非完全缺失。若要改进,可考虑添加 RangePicker 的对应对比测试。

  3. 第67-90行的测试无问题 - 该测试"should reset invalid partial input on blur without triggering onChange"是关于无效输入的重置行为,不是手动清空测试,其描述与实现相符。

实际需要改进的是:

  • RangePicker 测试缺少 onChange 断言 - 第165-265行的四个 RangePicker 测试(清空开始输入、结束输入、两个输入、输入值)都没有验证 onChange 的调用,而单选选择器测试则包含此断言,应保持一致。

Likely an incorrect or invalid review comment.

@alii13
Copy link
Author

alii13 commented Oct 31, 2025

@zombieJ thanks for your suggestions. I have resolved those changes, can you please do a re-review whenever you get time? Thanks!

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 allow manual clear

3 participants