refactor(Digit): remove proxyChange#9610
refactor(Digit): remove proxyChange#9610zzjiaxiang wants to merge 3 commits intoant-design:masterfrom
Conversation
…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.
📝 WalkthroughWalkthrough移除了 ProFormDigit 中的自定义代理输入处理(proxyChange)并直接将 fieldProps 传递给底层 InputNumber,修复了 min/max 边界在 onBlur 时的不一致行为;同时精简相关工具函数、更新测试,并在示例中新增一个带 percent 的 ProFormDigit 并缩短提交等待时长。 Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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 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} |
There was a problem hiding this comment.
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.
| ref={ref} | |
| ref={ref as React.Ref<any>} |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
demos/form/layout-change.tsx (1)
343-353: Demo label 大小写与其它字段不一致(minor)。同一表单中其它 label 均为 Title Case(如
Project Name、Business 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
📒 Files selected for processing (5)
demos/form/layout-change.tsxsrc/field/components/Digit/FieldDigitEdit.tsxsrc/field/components/Digit/digitUtils.tssrc/field/components/Digit/index.tsxtests/form/base.test.tsx
💤 Files with no reviewable changes (1)
- src/field/components/Digit/digitUtils.ts
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
…o "Percent" for consistency
fix #9601 close #8737
InputNumber 在时 onBlur 时做了很多验证的逻辑, ProFormDigit 代理了 onBlur 失去了部分验证.
proxyChang逻辑是为了解决这个问题 引进的.尝试移除这部分逻辑 ,发现 InputNumber 是可以正确处理该问题的.
这里的测试用例可以不需要的
Summary by CodeRabbit
发布说明
新功能
改进
重构
测试