Skip to content

refactor(Digit): remove proxyChange#9610

Open
zzjiaxiang wants to merge 3 commits intoant-design:masterfrom
zzjiaxiang:FieldDigitEdit
Open

refactor(Digit): remove proxyChange#9610
zzjiaxiang wants to merge 3 commits intoant-design:masterfrom
zzjiaxiang:FieldDigitEdit

Conversation

@zzjiaxiang
Copy link
Copy Markdown
Contributor

@zzjiaxiang zzjiaxiang commented Apr 26, 2026

fix #9601 close #8737
InputNumber 在时 onBlur 时做了很多验证的逻辑, ProFormDigit 代理了 onBlur 失去了部分验证.
proxyChang逻辑是为了解决这个问题 引进的.尝试移除这部分逻辑 ,发现 InputNumber 是可以正确处理该问题的.

这里的测试用例可以不需要的

Summary by CodeRabbit

发布说明

  • 新功能

    • 新增百分比数字输入字段,支持精度和范围配置(带百分号显示)
  • 改进

    • 加快表单提交反馈响应时间(由 2000ms 缩短至 500ms)
  • 重构

    • 简化数字输入组件实现,移除冗余的输入代理与校验处理逻辑
  • 测试

    • 调整相关表单输入与模糊交互测试以反映新行为

…gitEdit component

- Deleted the isEmptyOrWhitespace utility function as it was no longer needed.
- Simplified the FieldDigitEdit component by removing the proxyChange logic and directly passing fieldProps to InputNumber.
- Cleaned up imports in the index file to reflect the changes.
…ust submission wait time

- Introduced ProFormDigit for capturing percentage values with precision and an addon for '%' symbol.
- Reduced the wait time for form submission feedback from 2000ms to 500ms for improved user experience.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Apr 26, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

📝 Walkthrough

Walkthrough

移除了 ProFormDigit 中的自定义代理输入处理(proxyChange)并直接将 fieldProps 传递给底层 InputNumber,修复了 min/max 边界在 onBlur 时的不一致行为;同时精简相关工具函数、更新测试,并在示例中新增一个带 percent 的 ProFormDigit 并缩短提交等待时长。

Changes

Cohort / File(s) Summary
ProFormDigit 核心逻辑简化
src/field/components/Digit/index.tsx, src/field/components/Digit/FieldDigitEdit.tsx
移除 proxyChange 及自定义 onChange/onBlur 处理;改为直接传递 fieldPropsInputNumber,更新 ref 使用并删除相关输入拦截/归一化逻辑,从而让底层 clamp(min/max)行为恢复为原生表现。
工具函数清理
src/field/components/Digit/digitUtils.ts
删除不再使用的 isEmptyOrWhitespace 导出,文件内容已清空。
演示与测试调整
demos/form/layout-change.tsx, tests/form/base.test.tsx
示例中新增 ProFormDigit(percent,precision=2,范围1–10,显示 %)并将表单提交等待从 2000ms 缩短为 500ms;测试改为分步输入并多次触发 blur 以验证 blur 恢复到最后有效值的行为。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 标题 'refactor(Digit): remove proxyChange' 准确总结了主要变化,即移除 proxyChange 逻辑,与所有文件的改动内容相符。
Linked Issues check ✅ Passed 代码改动通过删除 proxyChange 逻辑,让 rc-input-number 的原生验证和 min/max 约束正常运行,完全满足 #9601#8737 的修复目标。
Out of Scope Changes check ✅ Passed 所有改动均围绕移除 proxyChange 逻辑的核心目标,包括移除工具函数、简化组件逻辑和更新测试,无超出范围的改动。
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 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 and usage tips.

Copy link
Copy Markdown
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 simplifies the Digit field component by removing custom input handling logic, specifically the proxyChange function and the isEmptyOrWhitespace utility, and instead passes fieldProps directly to the Ant Design InputNumber component. The changes also include updates to the layout-change demo and adjustments to the test suite to align with the new input behavior. One review comment identifies a potential TypeScript compilation issue resulting from the removal of a type cast on the ref prop in FieldDigitEdit.tsx.

<InputNumber<number | string>
ref={ref as React.Ref<any>}
<InputNumber
ref={ref}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The ref parameter is typed as React.Ref<unknown>, which is generally not assignable to the more specific ref types expected by InputNumber (typically React.Ref<HTMLInputElement>). Removing the as React.Ref<any> cast may lead to TypeScript compilation errors in environments with strict type checking. It is recommended to restore the cast to ensure compatibility.

Suggested change
ref={ref}
ref={ref as React.Ref<any>}

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (2)
demos/form/layout-change.tsx (1)

343-353: Demo label 大小写与其它字段不一致(minor)。

同一表单中其它 label 均为 Title Case(如 Project NameBusiness Manager),建议将 label="percent" 改为 Percent,保持视觉一致。

✏️ 建议修改
           <ProFormDigit
             name="percent"
-            label="percent"
+            label="Percent"
             width="xs"
             min={1}
             max={10}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@demos/form/layout-change.tsx` around lines 343 - 353, The ProFormDigit field
currently uses label="percent" which is inconsistent with other form labels in
Title Case; locate the ProFormDigit with name="percent" and change its label
prop to "Percent" so it matches the casing of other labels (e.g., Project Name,
Business Manager) and maintain visual consistency across the form.
tests/form/base.test.tsx (1)

3551-3601: 测试描述与新场景不再一致(minor)。

注释 // https://github.com/ant-design/pro-components/issues/5743 仍保留,但用例描述 submitted value should be consistent with input when precision=0 已不再准确——新流程是先建立合法 decimalValue=22.22,再输入非法字符串 '22.22.22',blur 后回退到上一次合法值并按 precision=0 取整。建议更新描述以反映“blur 时回退到 rc-input-number 内部 decimalValue + precision 处理”这一行为,避免后续维护者误解。

✏️ 建议描述调整
-  it(`📦 submitted value should be consistent with input when precision=0`, async () => {
+  it(`📦 blur should revert invalid input to last valid decimalValue with precision=0`, async () => {

另外,该用例本质上依赖 rc-input-number 内部 decimalValue 的回退语义(此 PR 的核心动机也正是把验证/钳制交还给底层),未来若 antd/rc-input-number 调整该行为,本用例会随之破坏,请知悉。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/form/base.test.tsx` around lines 3551 - 3601, Update the test title
string in the it(...) that currently reads "📦 submitted value should be
consistent with input when precision=0" to explicitly state that on blur the
field falls back to the rc-input-number internal decimalValue and then applies
precision rounding (e.g., "on blur fallback to last valid decimalValue and apply
precision=0 rounding"), and adjust or add a short inline comment near the
ProFormDigit/precision test setup to note this dependence on rc-input-number's
decimalValue rollback behavior (references: the it(...) test block,
ProFormDigit, decimalValue, precision, and the blur sequence in the test).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@demos/form/layout-change.tsx`:
- Around line 343-353: The ProFormDigit field currently uses label="percent"
which is inconsistent with other form labels in Title Case; locate the
ProFormDigit with name="percent" and change its label prop to "Percent" so it
matches the casing of other labels (e.g., Project Name, Business Manager) and
maintain visual consistency across the form.

In `@tests/form/base.test.tsx`:
- Around line 3551-3601: Update the test title string in the it(...) that
currently reads "📦 submitted value should be consistent with input when
precision=0" to explicitly state that on blur the field falls back to the
rc-input-number internal decimalValue and then applies precision rounding (e.g.,
"on blur fallback to last valid decimalValue and apply precision=0 rounding"),
and adjust or add a short inline comment near the ProFormDigit/precision test
setup to note this dependence on rc-input-number's decimalValue rollback
behavior (references: the it(...) test block, ProFormDigit, decimalValue,
precision, and the blur sequence in the test).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6e9bf0e8-84bd-48b6-a89f-b520c9dd02b2

📥 Commits

Reviewing files that changed from the base of the PR and between bdbf841 and de6530e.

📒 Files selected for processing (5)
  • demos/form/layout-change.tsx
  • src/field/components/Digit/FieldDigitEdit.tsx
  • src/field/components/Digit/digitUtils.ts
  • src/field/components/Digit/index.tsx
  • tests/form/base.test.tsx
💤 Files with no reviewable changes (1)
  • src/field/components/Digit/digitUtils.ts

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.48%. Comparing base (bdbf841) to head (b10ea7e).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9610      +/-   ##
==========================================
- Coverage   88.53%   88.48%   -0.05%     
==========================================
  Files         368      367       -1     
  Lines       11257    11225      -32     
  Branches     4157     4141      -16     
==========================================
- Hits         9966     9933      -33     
  Misses       1139     1139              
- Partials      152      153       +1     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

1 participant