NumberInput
Data inputA 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'; 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.
Without VAT. The value is 1250.
<script lang="ts">
import { Field, NumberInput } from '@limerdev/zest';
let amount: number | null = $state(1250);
</script>
<Field.Root class="w-full max-w-xs">
<Field.Label>Amount</Field.Label>
<NumberInput
name="amount"
bind:value={amount}
min={0}
step={50}
locale="sv-SE"
formatOptions={{ style: 'currency', currency: 'SEK' }}
/>
<Field.Description>Without VAT. The value is {amount ?? 'empty'}.</Field.Description>
</Field.Root> Formats
formatOptions takes Intl.NumberFormat options: a whole quantity, hours with one decimal, a percentage.
<script lang="ts">
import { Field, NumberInput } from '@limerdev/zest';
let seats: number | null = $state(12);
let hours: number | null = $state(7.5);
let discount: number | null = $state(0.1);
</script>
<div class="grid w-full max-w-xs gap-6">
<Field.Root>
<Field.Label>Seats</Field.Label>
<NumberInput
bind:value={seats}
min={1}
max={500}
locale="en-GB"
formatOptions={{ maximumFractionDigits: 0 }}
/>
</Field.Root>
<Field.Root>
<Field.Label>Hours</Field.Label>
<NumberInput
bind:value={hours}
min={0}
max={24}
step={0.5}
largeStep={4}
locale="en-GB"
formatOptions={{ minimumFractionDigits: 1, maximumFractionDigits: 2 }}
/>
</Field.Root>
<Field.Root>
<Field.Label>Discount</Field.Label>
<NumberInput
bind:value={discount}
min={0}
max={1}
step={0.05}
locale="en-GB"
formatOptions={{ style: 'percent' }}
/>
</Field.Root>
</div> States
Without steppers, invalid in its Field, and disabled.
<script lang="ts">
import { Field, NumberInput } from '@limerdev/zest';
</script>
<div class="grid w-full max-w-xs gap-6">
<Field.Root>
<Field.Label>Invoice number</Field.Label>
<NumberInput
value={1042}
steppers={false}
locale="en-GB"
formatOptions={{ useGrouping: false }}
/>
</Field.Root>
<Field.Root invalid>
<Field.Label>Hourly rate</Field.Label>
<NumberInput value={null} min={0} locale="en-GB" placeholder="0" />
<Field.Error>Enter a rate.</Field.Error>
</Field.Root>
<Field.Root disabled>
<Field.Label>Rounding</Field.Label>
<NumberInput value={5} locale="en-GB" />
</Field.Root>
</div> 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. |