Skip to content
Vertical Jump Designs-uiFront-End Studio
Get Pro

v3.9 is out.

Forms

NumberInput

Free15.7 KB gzipped

A 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

tsx
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

tsx
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.

tsx
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.

tsx
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.

tsx
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

tsx
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.

tsx
<Field label="Weight">
  <NumberInput min={0} step={2.5} endAddon="kg" defaultValue={60} />
</Field>

API reference

NumberInput

NumberInput props
PropTypeDefault
value

Controlled value. null means the field is empty.

number | null—
defaultValue

Initial value when uncontrolled.

number | nullnull
onValueChange

Called with the new number (or null when cleared) whenever the value changes: while typing a parseable number, stepping, and on blur/Enter when the value is clamped or rounded.

(value: number | null) => void—
min

Smallest allowed value. Stepping never goes below it; typed values are clamped on blur when clampOnBlur.

number—
max

Largest allowed value. Stepping never goes above it; typed values are clamped on blur when clampOnBlur.

number—
step

Amount added or removed by ArrowUp/ArrowDown and the stepper buttons.

number1
largeStep

Amount added or removed by PageUp/PageDown.

number10 × step
precision

Fixed number of decimal places. Committed values are rounded to it and the display shows exactly this many digits (unless formatOptions says otherwise). When omitted, the step's decimals are used for stepping.

number—
clampOnBlur

Clamp to min/max and round to precision when the field loses focus or Enter is pressed.

booleantrue
allowDecimal

Allow a decimal separator.

booleantrue, or false when `precision` is 0
allowNegative

Allow a minus sign.

booleantrue, or false when `min` is 0 or more
formatOptions

Intl.NumberFormat options for the value shown while the field is not focused (e.g. { style: "currency", currency: "USD" } or { style: "unit", unit: "percent" }). While focused the field shows the plain editable number. Note style: "percent" shows 0.45 as "45%"; use style: "unit", unit: "percent" to show 45 as "45%".

Intl.NumberFormatOptions—
locale

BCP 47 locale for formatting and parsing (group and decimal separators).

stringthe browser locale
stepper

Stepper button layout.

"sides""stacked""none""sides"
decrementLabel

Accessible name of the decrement button.

string"Decrease"
incrementLabel

Accessible name of the increment button.

string"Increase"
wheel

Change the value with the mouse wheel while the field is focused.

booleanfalse
ref

Ref to the <input> element.

Ref<HTMLInputElement>—
startIcon

Decorative icon before the text. Hidden from assistive technology.

ReactNode—
fullWidth

Stretches the field to fill its container.

booleantrue
variant

Visual style.

"outline""filled""outline"
size

Control height, padding, and type size. Inherits from a surrounding Field when not set.

"sm""md""lg""md"
radius

Corner rounding. When omitted, uses --field-radius. Use pill for search bars.

"none""xs""sm""md""lg""xl""2xl""pill"—
invalid

Marks the value as invalid: sets aria-invalid and a danger border. Pair it with a visible error message (a Field does this for you). Inherits from a surrounding Field.

booleanfalse
inputClassName

Class name for the <input> element. className goes to the wrapper.

string—
onClear

Called after the clear button empties the field (after onChange/onValueChange).

() => void—
startAddon

Static content attached to the start edge, such as "https://" or a currency symbol. Text addons are announced as part of the input's description (aria-describedby).

ReactNode—
endAddon

Static content attached to the end edge, such as ".com" or a unit ("kg"). Text addons are announced as part of the input's description.

ReactNode—
htmlSize

The native size attribute (visible width in characters). Mostly useful with fullWidth={false}.

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)

Running accessibility audit

Checking the examples above…

Lighthouse audit

Light mode

Score 100

37 passed · 0 failed · 28 not applicable · 10 to check by hand

Dark mode

Score 100

37 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

Keyboard
KeyAction
Arrow UpArrow DownIncreases or decreases by step.
Page UpPage DownIncreases or decreases by the large step.
HomeEndGoes to min or max, when set.
EnterCommits the typed value (and still submits a form).

Roles and states

Roles and states
ElementRoleStates and properties
<input>spinbuttonaria-valuenow, aria-valuemin, aria-valuemax, aria-valuetext
Step buttonsbuttonaria-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.

Manual accessibility checks
CheckWhat to testWCAG 2.2
KeyboardEvery 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)
FocusFocus 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 readersNames, 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)
ColorMeaning 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 reflowAt 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 targetsClick 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)
MotionAnimations respect the reduced-motion setting.2.3.3 (AAA)