Repository navigation
fix(module:input-number): make sure the displayed value is correct - #9312
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9312 +/- ##
=======================================
Coverage 92.12% 92.12%
=======================================
Files 561 561
Lines 19627 19631 +4
Branches 3106 3107 +1
=======================================
+ Hits 18082 18086 +4
Misses 1206 1206
Partials 339 339 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
||
| function defaultParser(value: string): number { | ||
| return parseFloat(value.trim().replace(/,/g, '').replace(/。/g, '.')); | ||
| const parsedValue = value.trim().replace(/,/g, '').replace(/。/g, '.'); |
There was a problem hiding this comment.
关键修复:在输入 1abc 这样的值时,输入前的显示值为 1,输入结束后又经过 parseFloat 将 1abc 格式化为了正确的值 1,导致输入前和输入后的值是一样的,angular 会忽略这个渲染更新。
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the input-number component to ensure the displayed value is correct during user input. The fix addresses an issue where the display value wasn't properly updated when users typed invalid characters or incomplete numbers.
- Moves the display value update to occur immediately when typing begins
- Conditionally applies formatting only when a formatter is provided during typing
- Improves the default parser to handle empty strings correctly
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| components/input-number/input-number.component.ts | Updates display value logic and improves default parser for empty strings |
| components/input-number/input-number.component.spec.ts | Adds test case for invalid input handling |
| components/input-number/demo/formatter.ts | Updates parser functions to use unary plus operator instead of parseFloat |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Issue Number: #9309
What is the new behavior?
Does this PR introduce a breaking change?
Other information