Skip to content

NumberInput

A number with its own step buttons.

import { NumberInput } from '@/design-system';

Examples

From 1 to 8.

In half hours.

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 min and max when 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.

NumberInput props
PropTypeDefaultDescription
valuenumber—The value, when you keep the state.
defaultValuenumber0The starting value.
onChange(value: number) => void—Called with each committed value.
minnumbernoneThe lowest value.
maxnumbernoneThe highest value.
stepnumber1How much each step changes it.
namestring—Sends the value with a form.
disabledbooleanfalseStops it being used.
idstringfrom FieldThe id of the control.
aria-labelstring—A name, when it is used without a Field.
classNamestring—Extra classes, for spacing or width.

Tokens

Tokens
TokenDefaultSets
--field-radius--radius-controlCorner radius of the closed control
--field-background--surfaceFill
--field-border--borderBorder colour
--field-font-size0.875remText size