NumberInput

Data input

A number field: <NumberInput> with bind:value (a number, or null when empty). It shows and reads numbers in the locale's way (sv-SE writes 1 234,5) with formatOptions (Intl.NumberFormat: currency, percent, decimals), keeps the value within min and max, and steps by step with the arrow keys and its buttons, by largeStep with Page Up and Page Down, and to min and max with Home and End. It is a WAI-ARIA spinbutton. With name, the form posts the plain number. Inside a Field it takes its id, label, description, error and invalid and disabled state from the Field.

import { NumberInput } from '@limerdev/zest';
NumberInput for AI tools (llms.txt)
Use for
Amounts, prices, quantities, hours, percentages: any number people type or nudge.
Don't
Numbers that aren't amounts, such as phone numbers, postcodes or card numbers: use Input (with inputmode="numeric"). A value chosen on a scale: use Slider. A one-time code: use PinInput.

Examples

Amount

An amount in kronor: typed and shown the Swedish way, posted as a plain number.

Formats

formatOptions takes Intl.NumberFormat options: a whole quantity, hours with one decimal, a percentage.

States

Without steppers, invalid in its Field, and disabled.

Props

Every part also takes class (merged over its defaults), ref (bindable: the element), children, and child (a snippet that renders your own element, with props to spread on it).

NumberInput

Prop Type Default Description
decrementLabel string the Config's `strings.decrease`, else 'Decrease' The decrease button's accessible name.
formatOptions NumberFormatOptions undefined How the number is shown: Intl.NumberFormat options, such as { style: 'currency', currency: 'SEK' } or { maximumFractionDigits: 2 }.
incrementLabel string the Config's `strings.increase`, else 'Increase' The increase button's accessible name.
largeStep number undefined How much Page Up and Page Down change the value.
locale string the Config's `defaultLocale`, else the browser's The locale that formats and parses the number (sv-SE writes 1 234,5). Set it in a server-rendered app, so the server and the browser agree.
max number undefined The largest value; typed values above it are lowered to it, and End goes to it.
min number undefined The smallest value; typed values below it are raised to it, and Home goes to it.
step number 1 How much an arrow key or a stepper button changes the value.
steppers boolean true Shows the increase and decrease buttons.
value bindable number | null null The number, or null when the field is empty. Bindable.