Skip to content

Commit

Permalink
[feat] input type number to input text with inputmode numeric
Browse files Browse the repository at this point in the history
  • Loading branch information
maximeperrault committed Jun 20, 2024
1 parent dffd42a commit 8b72e1c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/fields/NumberInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ export function NumberInput({
if (!onChange) {
return
}
if (nextValue === '') {
onChange(undefined)
}

const normalizedNextValueAsString = nextValue && nextValue.length ? nextValue : undefined
const nextValueAsNumber = Number(normalizedNextValueAsString)
const normalizedNextValue = !Number.isNaN(nextValueAsNumber) ? nextValueAsNumber : undefined

onChange(normalizedNextValue)
if (Number.isNaN(nextValueAsNumber)) {
return
}
onChange(nextValueAsNumber)
},
[onChange]
)
Expand Down Expand Up @@ -119,11 +123,13 @@ export function NumberInput({
$isTransparent={isTransparent}
disabled={disabled}
id={name}
inputMode="numeric"
maxLength="12"
onBlur={handleBlur}
onChange={handleChange}
onFocus={handleFocus}
readOnly={readOnly}
type="number"
type="text"
value={value ?? ''}
{...originalProps}
/>
Expand Down

0 comments on commit 8b72e1c

Please sign in to comment.