Number
A numeric input with rolling digits, accelerating steppers, bounds, affixes, and locale-aware formatting.
import { NumberInput } from '@uthereal/ui/number-input'Number input playground
Overview
NumberInput renders a labelled numeric field on Zag's number-input machine with rolling odometer digits. Each digit spins on its own wheel, and gained or lost places open or close smoothly. A decrease button sits at the start, the formatted value sits in the center, and an increase button sits at the end inside a shell 196px wide by default (164px small, 228px large).
The component parses and formats locale-aware decimals, currencies, and percentages, enforces min and max (0 to Number.MAX_SAFE_INTEGER by default), and emits a number or null when empty. Use NumberInput when the exact value matters, such as quantities, limits, or offsets. Use Range when visual position along a scale guides the selection.
Usage
'use client'
import { useState } from 'react'
import { NumberInput } from '@uthereal/ui/number-input'
export function Seats() {
const [seats, setSeats] = useState<number | null>(12)
return (
<NumberInput
label="Seats"
min={1}
max={500}
value={seats}
onValueChange={setSeats}
/>
)
}Omit value for an uncontrolled field initialized from defaultValue. Use onValueCommit to read the settled, clamped number on blur, Enter, label scrub release, or stepper and arrow-key release.
Examples
Formatting and units
Set format to decimal (default), currency (with an ISO 4217 currency code), or percent. Percent values are stored as fractions, so 0.15 displays as 15%. Set locale for deterministic separators and symbols; omit it to inherit the locale from UtherealProvider or fall back to en-US so server and browser output match. Use prefix or suffix for units announced with the value, and set scrub to drag the label sideways by one step every 6px.
Bounds and stepper modes
At min or max, the matching stepper dims with aria-disabled and stays focusable. Pressing it again strains the value toward the limit, shakes the stepper icon, announces the limit, and shows a brief note beside the label (limitHint). Typing above max tints the shell with --ui-warning immediately; typing below min waits 700ms so multi-digit drafts such as "1" on the way to "12" do not flash. Typed drafts snap to the step grid and clamp on blur, Enter, or the next step. Set a negative min to allow negative values, configure largeStep for Shift+arrow and PageUp/PageDown jumps, or set showSteppers={false} for plain numeric entry.
API reference
These serializable arguments and defaults come directly from the component schema.
| Argument | Type / default | Description |
|---|---|---|
label | stringDefault: "Quantity" | Visible label and accessible name. Name the information asked for, in sentence case. |
hideLabel | booleanDefault: false | Hide the label visually when the context already names the field. It is still announced. |
description | string— | Supporting text below the field, announced with it. Use it for format hints and constraints. |
error | string— | Validation message from your application. Setting it marks the field invalid; the message is linked to the field and announced politely. |
required | booleanDefault: false | Marks the field as required for assistive technology and shows an indicator. Your application validates the value. |
readOnly | booleanDefault: false | The value can be focused, selected, and copied, but not edited. It is still submitted with a form. |
disabled | booleanDefault: false | Unavailable and removed from the tab order. A disabled field is not submitted with a form. |
name | string— | Native form field name, submitted with the value in a form. |
placeholder | string— | Example text while the field is empty. Never a substitute for the label. |
defaultValue | number | nullDefault: 0 | Initial number (0 by default), or null for an empty field. Later argument edits do not reset an existing instance; use value and onValueChange to control it. |
min | numberDefault: 0 | Lowest allowed value, 0 by default; set a negative minimum to allow negative numbers. A typed value below it warns after a moment and is clamped on blur. |
max | numberDefault: 9007199254740991 | Highest allowed value; the default is the largest safe integer, which means no practical limit (End then moves the caret). A typed value above it warns at once and is clamped on blur. |
step | numberDefault: 1 | Amount added or removed by the arrow keys and steppers. |
largeStep | number— | Amount added or removed by Page Up/Down and Shift with an arrow. Omit it for ten steps. |
prefix | string— | Text before the number, such as "$". It is announced with the value and shown in the secondary text color. |
suffix | string— | Text after the number, such as " seats" (include the space). It is announced with the value. |
scrub | booleanDefault: false | Let the label be dragged sideways to change the value, one step every 6 pixels. The arrow keys stay the keyboard path. |
limitHint | booleanDefault: true | Show a brief note beside the label ("Max 500") when a press meets a limit or a typed value passes one. |
minHintLabel | stringDefault: "Min {limit}" | Text of the limit note at the minimum. {limit} is the formatted minimum. |
maxHintLabel | stringDefault: "Max {limit}" | Text of the limit note at the maximum. {limit} is the formatted maximum. |
minReachedLabel | stringDefault: "{value}, minimum" | Announced politely when a step meets the minimum. {value} is the formatted value. |
maxReachedLabel | stringDefault: "{value}, maximum" | Announced politely when a step meets the maximum. {value} is the formatted value. |
format | NumberFormat— | Display format: style decimal, percent (the value 0.25 shows as 25%) or currency (with an ISO currency code), and fraction digits. |
locale | string— | BCP 47 locale for decimal and group separators and currency symbols, e.g. en-US or de-CH. Omit it to use the application locale (UtherealProvider), else en-US; never the browser’s, so server and browser render the same text. |
showSteppers | booleanDefault: true | Show the decrease button at the start of the field and the increase button at the end. |
allowMouseWheel | booleanDefault: false | Let the mouse wheel change the value while the field has focus. |
decrementLabel | stringDefault: "Decrease {label}" | Accessible name of the decrease button. {label} is the field label ("Decrease Seats"). |
incrementLabel | stringDefault: "Increase {label}" | Accessible name of the increase button. {label} is the field label ("Increase Seats"). |
variant | outline | soft | ghostDefault: "outline" | Field surface: outline for forms, soft on busy surfaces, ghost for inline editing without a border. |
size | sm | md | lgDefault: "md" | Field height and text size: 32, 36, or 46 pixels. Matches the button and dropdown trigger of the same size. |
recipe | studio | softDefault: "studio" | Visual treatment. Both recipes use the same interaction behavior. |
theme | NumberInputTheme— | Color mode, accent, and semantic tokens. See Theming for all keys and defaults. |
motion | none | subtle | expressiveDefault: "subtle" | Rolling digits, the limit strain and note, message copy and state colors. Reduced motion keeps short fades; none makes every change immediate. |
dir | ltr | rtl— | Reading direction. Omit it to inherit the page direction. |
React integration
| Prop | Purpose |
|---|---|
value, onValueChange | Controlled value (number | null). onValueChange fires in both modes. |
onValueCommit(value) | Settled, clamped value on blur, Enter, scrub release, or key/step release. |
ref | Ref to the native <input> element. |
preset | Application defaults (such as locale and format), overridden by props. |
tokens | CSS custom properties (--ui-*) applied after the typed theme. |
renderIcon(name, context) | Custom stepper icon renderer; slot is 'decrement' or 'increment'. |
className, style | Applied to the root field element, which carries the resolved tokens. |
| Native attributes | Forwarded to <input> (onBlur, onKeyDown, autoFocus, aria-*). |
Keyboard & accessibility
| Key | Interaction |
|---|---|
ArrowUp, ArrowDown | Step by one step. Holding repeats after 400ms and accelerates down to 40ms. |
Shift + arrows, PageUp/PageDown | Step by largeStep (10 × step when omitted). |
Home, End | Jump to min or max. End moves the caret when max is unbounded. |
Enter | Commit the typed draft, or select the value when not editing. |
Escape | Cancel an open typed draft and restore the value from before editing. |
The input exposes role="spinbutton" with aria-valuemin, aria-valuemax (omitted when unbounded), and the formatted value plus affixes in aria-valuetext. Stepper buttons derive their accessible names from decrementLabel and incrementLabel, remain in the tab order, and preserve focus on pointer press. At a bound, steppers set aria-disabled="true" instead of disabled so keyboard users can still reach them and trigger feedback. Stepper changes and limit hits announce in a polite aria-live="polite" region.
The virtual keyboard (inputMode) selects text when min < 0, decimal when step, min, or format permits fraction digits, and numeric otherwise. All spacing and borders use logical CSS properties for dir="rtl", and forced-colors: active preserves focus outlines, disabled colors, and value contrast.
Motion and theming
- Rolling digits: each digit wheel turns on the snappy spring through a subtle motion blur. New place columns open width on the morph spring and close on the smooth spring.
- Affixes and centering: prefix and suffix characters enter one character at a time, and the centered value group glides on the morph spring when typing changes its width.
- Steppers and limits: active stepper glyphs scale to
0.82over90msand release on the CSS spring curve. Presses past a limit kick the value toward the boundary with escalating velocity, shake the refused stepper icon, and rise the limit note beside the label. - Scrubbing resistance: dragging the label past
minormaxapplies rubber-band travel and springs back on release. - Reduced motion:
prefers-reduced-motion: reducedisables wheel travel, glyph scale, and strain kicks, keeping120msfades and a brief limit color tint.motion="none"makes all updates immediate (0ms).
theme accepts the core and control token groups, plus borderStrong, warning, and four component tokens: width (--ui-number-input-width), stepperSize (--ui-number-input-stepper-size), inset (--ui-number-input-inset), and limitMix (--ui-number-input-limit-mix).
Composition
NumberInput is a leaf component. Its numeric value (number | null) is host state at /fields/instance-<id>/value. Stored finite numbers and null survive configuration edits. See Building with agents.
{
"type": "NumberInput",
"props": {
"label": "Monthly budget",
"prefix": "$",
"step": 100,
"defaultValue": 1200
},
"children": []
}