NumberInput
import { NumberInput } from '@yarcl/react';Between 1 and 12 people.
Saved as 12.50.
<Field label="Guests" description="Between 1 and 12 people."> <NumberInput min={1} max={12} defaultValue={2} /></Field>
<Field label="Price"> <NumberInput value={price} onValueChange={setPrice} min={0} step={0.5} /></Field>- The value is a
number, ornullwhen the input is empty. UsevalueandonValueChangeto control it, ordefaultValueto leave it uncontrolled. - Typed text is committed on blur or
Enter: it’s clamped tominandmax, and text that isn’t a number reverts to the last value. Inside a form, the firstEntercommits the typed text without submitting; a secondEntersubmits the form. size,radiusandcolorwork like Input. They share a base height unless either component overrides it, andcolorsets the focus border and ring. Defaults come fromcomponents.NumberInput, thendefaults.- Inside a Field it’s labelled, described and marked invalid automatically.
Accessibility
Section titled “Accessibility”- The input has the
spinbuttonrole witharia-valuenow,aria-valueminandaria-valuemax. ArrowUpandArrowDownstep bystep,PageUpandPageDownby ten steps, andHomeandEndjump tominandmax.- The stepper buttons are labelled (
incrementLabel,decrementLabel) and left out of the tab order, since the arrow keys do the same. Clicking them keeps focus where it was.
Accepts every native <input> attribute except color, size, type, value, defaultValue, onChange, min, max and step, which are replaced by the props below. className and style apply to the outer box; everything else goes to the input.
| Prop | Type | Default | Description |
|---|---|---|---|
color | Colorconfig | config.defaults.color | Semantic color, from the colors config. |
decrementLabel | string | config.labels.decrease | Accessible label of the decrement button. |
defaultValue | number | null | null | Initial value when uncontrolled. |
incrementLabel | string | config.labels.increase | Accessible label of the increment button. |
max | number | Highest allowed value. Typed values are clamped to it, and End jumps to it. | |
min | number | Lowest allowed value. Typed values are clamped to it, and Home jumps to it. | |
onValueChange | (value: number | null) => void | Called with the new value after a step, or when typed text is committed on blur or Enter. The first Enter commits without submitting a form; a second Enter submits it. | |
radius | 'size' | Radiusconfig | config.defaults.radius | Border radius, from the radii config, or 'size' for the radius named like the control's size. |
size | 'lg' | 'xs' | 'sm' | 'md' | 'xl' | config.defaults.size | Control size, from the sizes config. |
step | number | 1 | Amount added or removed by the stepper buttons and the arrow keys. PageUp and PageDown step ten times as far. |
value | number | null | Controlled value. null means the input is empty. |