NumberInput
A number with its own step buttons.
import { NumberInput } from '@/design-system';Examples
import { Field, NumberInput } from '@/design-system';
export default function NumberInputBasic() {
return (
<div className="grid gap-4 sm:grid-cols-2">
<Field label="Guests" hint="From 1 to 8.">
<NumberInput name="guests" defaultValue={2} min={1} max={8} />
</Field>
<Field label="Hours" hint="In half hours.">
<NumberInput defaultValue={1.5} min={0} step={0.5} />
</Field>
</div>
);
}How it works
- Arrow Up and Down step the value. Home and End go to
minandmaxwhen they are set. - Typing is free until the input loses focus or Enter is pressed. The value is then kept within the limits; text that is not a number is dropped.
- It always holds a number, so it cannot be left empty.
Props
NumberInput takes only these props.
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | — | The value, when you keep the state. |
defaultValue | number | 0 | The starting value. |
onChange | (value: number) => void | — | Called with each committed value. |
min | number | none | The lowest value. |
max | number | none | The highest value. |
step | number | 1 | How much each step changes it. |
name | string | — | Sends the value with a form. |
disabled | boolean | false | Stops it being used. |
id | string | from Field | The id of the control. |
aria-label | string | — | A name, when it is used without a Field. |
className | string | — | Extra classes, for spacing or width. |
Tokens
| Token | Default | Sets |
|---|---|---|
--field-radius | --radius-control | Corner radius of the closed control |
--field-background | --surface | Fill |
--field-border | --border | Border colour |
--field-font-size | 0.875rem | Text size |