Skip to content

Commit

Permalink
fix(input-number): the problem that the negative sign is replaced whe…
Browse files Browse the repository at this point in the history
…n the negative sign is entered (#6281)

Co-authored-by: 07akioni <[email protected]>
  • Loading branch information
jahnli and 07akioni authored Nov 24, 2024
1 parent 5c2b9d6 commit 968f3bb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Fixes

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

### Features

Expand Down
6 changes: 4 additions & 2 deletions src/input-number/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}

Expand Down

0 comments on commit 968f3bb

Please sign in to comment.