Line total€2,621.50€20123456789,601234567892012345678910123456789.5012345678900123456789€99,999.00
number-input · , lively
number-input-demo.tsx
When to use
Use for a single number adjusted in small steps. Digits roll, a note says which bound stopped the change, and a meter can show stock left toward max. Presets: stepper, compact, scrub.
When not to use
For a value picked along a continuous range use Slider. For free text use Text Field.
Use it for a single number the person adjusts in small amounts: quantities on an order line, a unit price,
a percentage, a radius in a theme editor, a reorder point in an inventory table. For a value picked along a
continuous range where the exact number matters less, use a slider. For free text, use a text field.
Only the digits that change travel. Press +: the button stretches under the finger (charge), the
changed digit rolls up on the small spring while the others stay (action), and it settles with the
temperament's bounce (settle). Hold the button and the digits roll faster and faster while the held
button's rim lights up with the speed. At min or max the value does not move: the digits are thrown
2 px against that wall, the rim lights at that end, the button at that end rests slightly compressed and
a note ("Max 120 pcs") rises under the field, so the limit is felt and explained, never a silent clamp.
With meter, a thin bar under the field fills from min toward max and the right side reads what is
left ("14 left"). Past 90% it turns warning: the stock, seats or quota running out is visible before
anyone hits the wall.
value and onValueChange control the number (null is an empty field); defaultValue makes it
uncontrolled. format takes Intl.NumberFormat options, so currency, grouping and percent are formatted and
parsed for the locale. Typing is plain text: the value is parsed, clamped to min/max, rounded to
precision and formatted on Enter or blur; a typed value past a bound is clamped and the bound's note says
why. name submits the raw number through a hidden input.
The field shares its states with Text Field: description is helper text,
error fills the rim with destructive from the bottom edge (it never shakes) and shows the message,
valid sweeps the rim to success from the left and traces a check, and required adds the 4 px dot after
the label. Only one message line shows at a time: error first, then the bound's note, then the valid
message, then the description, so nothing below the field jumps.
<NumberInput label="Quantity" unit="pcs" min={1} max={stock} meter limitMessage={{ max: `All ${stock} in stock` }} error={quantity > budget ? "Over the order budget" : undefined} value={quantity} onValueChange={setQuantity}/>
limitMessage replaces the default "Max 120 pcs" / "Min 1 pcs" notes, or turns them off with false.
meterLabel renders the right side of the meter; it receives the remaining number and its rolling
digits: meterLabel={(n, digits) => <>{digits} seats left</>}.
The note, the meter and the valid state use the success and warning tokens, shipped in the item's
cssVars (the same values as Text Field).
Three layout presets share one look and one motion:
<NumberInput preset="stepper" /> {/* − and + balls at both ends, value centred (default) */}<NumberInput preset="compact" /> {/* stacked chevrons at the right end, value left aligned */}<NumberInput preset="scrub" /> {/* no buttons: drag the unit grip sideways to change the value */}
The scrub grip shows a small chevron on each side at rest, so "drag sideways" is readable before the
first drag.
Set the character for the whole app with MotionKitProvider, or per field with temperament. At calm
the digits roll with no bounce and holding a button accelerates gently; the wall kick stays.
The scrub preset turns the unit into a grip ball. Drag it sideways: the ball stretches toward the drag,
the value follows the distance in steps (6 px per step) and the digits roll; let go and the ball is thrown
back to its stop. Vertical drags still scroll the page on touch screens.
The input is a role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and
aria-valuetext (the formatted value plus a text unit). Give it a label (a real <label>) or an
aria-label.
The rolling digits are aria-hidden: the formatted value is read once, from the input.
The + and − buttons are labelled "Increase" and "Decrease", point at the input with
aria-controls and stay out of the tab order (the arrow keys do the same job). At a bound they get
aria-disabled. Stepper balls are 28 px at sm and larger above; their icons are aria-hidden.
The scrub grip is a button in the tab order that also takes the arrow keys.
description, error, the bound's note, the valid message and the meter's "left" text are linked to the
input with aria-describedby; the error, note and valid lines are aria-live="polite", so a clamp or
a bound is announced. error sets aria-invalid; required sets aria-required (the dot is
aria-hidden). The meter bar is aria-hidden: what is left is read as text.
Message words stay foreground or destructive (AA in any theme); the success and warning colours
ride on icons, dots and the bar only.
Focus lights the rim with ring; keyboard focus adds a 3 px halo. aria-invalid turns the rim
destructive. Colors come from your theme, so contrast follows it in light and dark.
disabled shows a muted tile; readOnly keeps the value readable and focusable without changes.
Steps the value by step; at a bound the digits kick against that wall
Shift + ArrowUp / ArrowDown
Steps by bigStep (10 steps by default)
PageUp / PageDown
Steps by 10 steps
Home / End
Jumps to min / max when they are set
Enter
Commits the typed text (parsed, clamped and formatted)
ArrowLeft / ArrowRight (scrub grip)
Steps the value down / up from the grip
Your onKeyDown runs first: if it calls event.preventDefault(), the component skips its own handling.
onFocus, onBlur and onWheel are composed, never replaced.
With reduced motion (the OS setting, or MotionKitProvider reducedMotion="always") the changed digits
crossfade in place instead of rolling, the buttons and the grip do not stretch, the wall kick and the
bound compression are off, the error and success rims fade instead of sweeping, the check is drawn at
once, messages fade in place and the meter eases in a short fade. The rim at a bound still lights and its
note still appears, so the limit stays visible, and holding a button still repeats.
Digits, the wall kick and the grip ball animate transform and opacity on motion values; only the
changed digits move. The digits sit in an absolutely positioned layer over the input, so stepping never
shifts the layout.
Holding a button runs one requestAnimationFrame loop, cancelled on release, leave, blur and unmount.
While the person types, the native text is shown and the rolling layer is hidden: rolling happens only on
step, hold, scrub and blur.
Main spring of each temperament. Set it with the temperament prop or MotionKitProvider; the default is lively.
Size
Not measured yet · budget 15.0 kB gzip
Component and MotionKit helpers; excludes react, react-dom, motion.
Dependencies
motion · peer
Triggers
press, drag, keyboard focus
Reduced motion
Changed digits crossfade instead of rolling, the wall kick, bound compression and grip stretch are off, rim sweeps and messages fade in place, the meter eases in a short fade; the bound's rim still lights and holding a button still repeats.
Keyboard
ArrowUp / ArrowDown
Steps the value by `step`; at a bound the digits kick against that wall
Shift + ArrowUp / ArrowDown
Steps by `bigStep` (10 steps by default)
PageUp / PageDown
Steps by 10 steps
Home / End
Jumps to `min` / `max` when they are set
Enter
Commits the typed text (parsed, clamped and formatted)
ArrowLeft / ArrowRight (scrub grip)
Steps the value down / up from the grip
Browsers
Last 2 versions of Chrome, Edge, Firefox and Safari (iOS 16.4+)