mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-04-06 14:30:46 +08:00
fix(input-number): correct wip value computing
This commit is contained in:
parent
0c921f4e53
commit
cdbbd8eb0c
@ -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
|
||||
|
@ -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'
|
||||
)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user