Skip to content

Commit 16d561d

Browse files
committedJan 31, 2025·
Updated <Input type="number" /> behavior to result in the same behavior as <Input number />
1 parent 8e8b560 commit 16d561d

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed
 

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@near-pagoda/ui",
3-
"version": "3.1.3",
3+
"version": "3.1.4",
44
"description": "A React component library that implements the official NEAR design system.",
55
"license": "MIT",
66
"repository": {

‎src/components/Input.README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ This will apply a default search icon on the left and fully rounded corners. The
2020

2121
## Number
2222

23-
By default, an input will emit a `string` value. However, you can use the `number` prop to emit a `number` value and configure if decimal or negative numbers are allowed.
23+
By default, an input will emit a `string` value. However, you can use `type="number"` or the `number` prop to emit a `number` value and configure if decimal or negative numbers are allowed.
2424

2525
```tsx
26-
<Input label="My Number" number name="myInput" />
26+
<Input label="My Number" type="number" name="myInput" />
2727
<Input label="My Number" number={{allowDecimal: false, allowNegative: false}} name="myInput" />
2828
```
2929

‎src/components/Input.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,23 @@ export const Input = forwardRef<HTMLInputElement, Props>(
3939
right,
4040
style,
4141
success,
42-
type = 'text',
4342
...props
4443
},
4544
ref,
4645
) => {
47-
const isNumber = Boolean(number);
46+
const isNumber = Boolean(number) || props.type === 'number';
4847
const assistiveTextId = `${name}-assistive-text`;
4948
const variant: ThemeInputVariant = error ? 'error' : success ? 'success' : 'default';
49+
let type = props.type || 'text';
50+
51+
if (isNumber) {
52+
/*
53+
A native number input (<input type="number" />) has all kinds of issues and limitations.
54+
We can combine <input type="text" input-mode="decimal" /> with numberInputHandler() for
55+
a better experience (DX and UX).
56+
*/
57+
type = 'text';
58+
}
5059

5160
if (type === 'search' && !iconLeft) {
5261
iconLeft = <MagnifyingGlass weight="bold" />;

0 commit comments

Comments
 (0)
Please sign in to comment.