Skip to content

Commit

Permalink
fix(comp:input-number): check whether value is a number (#1250)
Browse files Browse the repository at this point in the history
  • Loading branch information
imguolao committed Nov 3, 2022
1 parent b263b79 commit 75c9fe1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/components/input-number/src/useInputNumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ export function useInputNumber(props: InputNumberProps, config: InputNumberConfi

function updateDisplayValueFromAccessor() {
const { value } = accessor
if (value === null || value === undefined) {
// Check whether value is empty.
if ((!value && value !== 0) || !String(value).trim()) {
displayValue.value = ''
} else if (Number.isNaN(value)) {

// Check whether value is not a number.
} else if (Number.isNaN(Number(value)) || (typeof value !== 'number' && typeof value !== 'string')) {
displayValue.value = ''
if (__DEV__) {
Logger.warn('components/input-number', `model value(${value}) is not a number.`)
}
} else {
if (displayValue.value === '' || value !== Number(displayValue.value)) {
displayValue.value = value.toFixed(precision.value)
const newValue = Number(value)
if (displayValue.value === '' || newValue !== Number(displayValue.value)) {
displayValue.value = newValue.toFixed(precision.value)
}
}
}
Expand Down

0 comments on commit 75c9fe1

Please sign in to comment.