fix(input-number): correct wip value computing

This commit is contained in:
07akioni 2024-11-25 21:53:06 +08:00
parent 0c921f4e53
commit cdbbd8eb0c
2 changed files with 10 additions and 6 deletions

View File

@ -7,7 +7,7 @@
### Fixes
- Fix `n-time-picker`'s `use-12-hours` type error warning, closes [#4308](https://github.com/tusen-ai/naive-ui/issues/4308)
- Fix `input-number` the problem that the negative sign is replaced when the negative sign is entered
- Fix `input-number` the problem that the negative sign is replaced when the negative sign is entered.
- Fix `n-data-table`'s header will show scrollbar in some old browsers, closes [#6557](https://github.com/tusen-ai/naive-ui/issues/6557).
### Features

View File

@ -11,13 +11,17 @@ export function parse(value: string): number | null {
return Number(value)
}
// can be parsed to number but shouldn't be applied when inputing
// when value includes `.`, ending with 0 and`.`, doesn't update, if 0 parse func will remove 0
// allow negative sign
// This function is created for `update-value-on-input` prop. When the prop is
// true, the input value will update the value and <input />'s value at the same
// time. So we need to make user's content won't be replaced by its parsed value
// in some certain cases. For example '0.' should be parsed and replaced by '0',
// '-0' should be parsed and replaced by '0', since user may input '-0.1' after.
export function isWipValue(value: string): boolean {
return (
(value.includes('.') && /^-?\d*\.?\d*$/.test(value))
|| /^-?\d*$/.test(value)
(value.includes('.')
&& (/^(-)?\d+.*(\.|0)$/.test(value) || /^(-)?\.\d+$/.test(value)))
|| value === '-'
|| value === '-0'
)
}