Forms
NumberInput
Free15.7 KB gzippedA numeric text field following the WAI-ARIA spinbutton pattern. The <input> itself is the spinbutton: it takes focus, exposes aria-valuenow/min/max/valuetext, and handles ArrowUp/Down, PageUp/Down, Home/End, and Enter. Stepper buttons are pointer conveniences (press and hold to repeat) and stay out of the tab order.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · Keys: Arrow Up, Arrow Down, Page Up and 4 more · Full report
Import
import { NumberInput } from "@vjdesigns/vjdesigns-ui";
Importing only NumberInput adds about 15.7 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Basic
Step with the buttons, the arrow keys (Shift for largeStep) or Page Up/Down. Values clamp to min and max on blur.
Value: 2
import { useState } from "react";
import { Field, NumberInput, Stack, Text } from "@vjdesigns/vjdesigns-ui";
export function Basic() {
const [guests, setGuests] = useState<number | null>(2);
return (
<Stack gap={3} style={{ width: "100%", maxWidth: "14rem" }}>
<Field label="Guests">
<NumberInput value={guests} onValueChange={setGuests} min={1} max={12} />
</Field>
<Text size="sm" tone="muted">
Value: <code>{String(guests)}</code>
</Text>
</Stack>
);
}
Formatted
formatOptions formats the value with Intl.NumberFormat while keeping a plain number as the value.
import { Field, NumberInput, Stack } from "@vjdesigns/vjdesigns-ui";
export function Formatted() {
return (
<Stack gap={5} style={{ width: "100%", maxWidth: "16rem" }}>
<Field label="Budget">
<NumberInput defaultValue={2500} step={100} min={0} formatOptions={{ style: "currency", currency: "USD" }} />
</Field>
<Field label="Discount">
<NumberInput defaultValue={0.15} step={0.05} min={0} max={1} formatOptions={{ style: "percent" }} stepper="stacked" />
</Field>
</Stack>
);
}
Accessibility
The stepper buttons are named by decrementLabel and incrementLabel. Arrow keys step by step, Page Up and Page Down by largeStep, and the value clamps to min and max when the field loses focus.
Up to 8 per booking.
import { Field, NumberInput } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<div style={{ width: "100%", maxWidth: "14rem" }}>
<Field label="Guests" hint="Up to 8 per booking.">
<NumberInput defaultValue={2} min={1} max={8} largeStep={4} decrementLabel="Remove a guest" incrementLabel="Add a guest" />
</Field>
</div>
);
}
Translated
Group and decimal separators follow the locale: German shows 1.234,50 € and accepts a comma as the decimal point. The stepper buttons' names come from the locale too.
import { Field, NumberInput, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import de from "@vjdesigns/vjdesigns-ui/locales/de";
export function Translated() {
return (
<LocaleProvider locale="de" messages={de}>
<div style={{ width: "100%", maxWidth: "16rem" }}>
<Field label="Betrag">
<NumberInput defaultValue={1234.5} step={10} formatOptions={{ style: "currency", currency: "EUR" }} />
</Field>
</div>
</LocaleProvider>
);
}
Right to left
The first example again, inside a right-to-left LocaleProvider (Arabic). Layout, spacing and arrow icons mirror, and the components' built-in text is translated. The example's own text stays in English.
Basic
Value: 2
import { LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
// Basic is the "Basic" example above.
<LocaleProvider locale="ar" messages={ar}>
<Basic />
</LocaleProvider>
Usage notes
Shows a formatted value (Intl.NumberFormat) when not focused and the plain editable number while focused; parses locale input (group separators, decimal comma). Built on Input, so size, variant, radius, addons, and Field wiring match every other text field.
<Field label="Weight">
<NumberInput min={0} step={2.5} endAddon="kg" defaultValue={60} />
</Field>
API reference
NumberInput
| Prop | Type | Default |
|---|---|---|
valueControlled value. | number | null | — |
defaultValueInitial value when uncontrolled. | number | null | null |
onValueChangeCalled with the new number (or | (value: number | null) => void | — |
minSmallest allowed value. Stepping never goes below it; typed values are clamped on blur when | number | — |
maxLargest allowed value. Stepping never goes above it; typed values are clamped on blur when | number | — |
stepAmount added or removed by ArrowUp/ArrowDown and the stepper buttons. | number | 1 |
largeStepAmount added or removed by PageUp/PageDown. | number | 10 × step |
precisionFixed number of decimal places. Committed values are rounded to it and the display shows exactly this many digits (unless | number | — |
clampOnBlurClamp to | boolean | true |
allowDecimalAllow a decimal separator. | boolean | true, or false when `precision` is 0 |
allowNegativeAllow a minus sign. | boolean | true, or false when `min` is 0 or more |
formatOptions
| Intl.NumberFormatOptions | — |
localeBCP 47 locale for formatting and parsing (group and decimal separators). | string | the browser locale |
stepperStepper button layout. | "sides""stacked""none" | "sides" |
decrementLabelAccessible name of the decrement button. | string | "Decrease" |
incrementLabelAccessible name of the increment button. | string | "Increase" |
wheelChange the value with the mouse wheel while the field is focused. | boolean | false |
refRef to the | Ref<HTMLInputElement> | — |
startIconDecorative icon before the text. Hidden from assistive technology. | ReactNode | — |
fullWidthStretches the field to fill its container. | boolean | true |
variantVisual style. | "outline""filled" | "outline" |
sizeControl height, padding, and type size. Inherits from a surrounding | "sm""md""lg" | "md" |
radiusCorner rounding. When omitted, uses | "none""xs""sm""md""lg""xl""2xl""pill" | — |
invalidMarks the value as invalid: sets | boolean | false |
inputClassNameClass name for the | string | — |
onClearCalled after the clear button empties the field (after | () => void | — |
startAddonStatic content attached to the start edge, such as | ReactNode | — |
endAddonStatic content attached to the end edge, such as | ReactNode | — |
htmlSizeThe native | number | — |
Also accepts standard HTML attributes, plus className, style and ref.
See what changed in each version in the Changelog.
Accessibility report
NumberInput targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Dark mode
Score 10037 passed · 0 failed · 28 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
| Key | Action |
|---|---|
| Arrow UpArrow Down | Increases or decreases by step. |
| Page UpPage Down | Increases or decreases by the large step. |
| HomeEnd | Goes to min or max, when set. |
| Enter | Commits the typed value (and still submits a form). |
Roles and states
| Element | Role | States and properties |
|---|---|---|
<input> | spinbutton | aria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext |
| Step buttons | button | aria-label, aria-controls → input; not tab stops |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |