Number input
A number with minus and plus buttons, read and written in the locale.
import { NumberInput } from "@forgeron/ui";import { NumberInput } from "@forgeron/ui";
import { useState } from "react";
export default function Stepper() {
const [seats, setSeats] = useState<number | null>(5);
return <NumberInput label="Seats" value={seats} onChange={setSeats} min={1} max={500} />;
}kg
kg
import { NumberInput } from "@forgeron/ui";
export default function Locale() {
return (
<div style={{ display: "grid", gap: 8 }}>
<NumberInput
label="Weight, French"
locale="fr-FR"
suffix="kg"
step={0.5}
defaultValue={1234.5}
/>
<NumberInput
label="Weight, English"
locale="en-US"
suffix="kg"
step={0.5}
defaultValue={1234.5}
/>
<NumberInput
label="Discount"
format={{ style: "percent" }}
step={0.05}
min={0}
max={1}
defaultValue={0.15}
/>
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the field for assistive technology. |
value / defaultValue | number | null | — | Controlled or not. |
onChange | (value: number | null) => void | — | On blur, Enter and every step. |
min / max | number | — | Clamped on commit and on steps. |
step / largeStep | number | 1 / 10 × step | Arrows and buttons; Page keys and Shift. |
locale | string | the device's | `fr-FR` reads 1 234,5. |
format | Intl.NumberFormatOptions | — | { style: "percent" }, { maximumFractionDigits: 2 }. |
prefix / suffix | ReactNode | — | A unit or a symbol inside the field. |
buttons | boolean | true | The minus and plus buttons. |
readOnly | boolean | — | Shown, not editable. |
disabled | boolean | — | Not editable. |
id / aria-describedby / aria-invalid | string / string / boolean | — | From `Field`'s function form: the label, hint and error stay tied. |
className | string | — | Extra classes. |