fix(input-number): the problem that the negative sign is replaced when the negative sign is entered (#6281)

Co-authored-by: 07akioni <07akioni2@gmail.com>
This commit is contained in:
jahnli 2024-11-24 19:51:56 +08:00 committed by GitHub
parent 5c2b9d6ac9
commit 968f3bbd6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 2 deletions

View File

@ -7,6 +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
### Features

View File

@ -7,6 +7,7 @@
### Fixes
- `n-time-picker``use-12-hours` 类型错误警告,关闭 [#4308](https://github.com/tusen-ai/naive-ui/issues/4308)
- 修复 `input-number` 存在负号时被替换的问题
### Features

View File

@ -13,10 +13,12 @@ export function parse(value: string): number | null {
// 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
export function isWipValue(value: string): boolean {
return (
value.includes('.')
&& (/^(-)?\d+.*(\.|0)$/.test(value) || /^\.\d+$/.test(value))
value === '-'
|| (value.includes('.') && /^-?\d*\.?\d*$/.test(value))
|| /^-?\d*$/.test(value)
)
}