Components

Number Input

An accessible React number input with − / + stepper buttons and digits that roll like an odometer when the value changes: min, max and step, press-and-hold to repeat, Arrow / PageUp / PageDown keys, optional mouse wheel and Intl.NumberFormat for currency, percent and units — a real input with spinbutton semantics, built with Tailwind CSS and Motion.

  • Rolling digits
  • Press & hold
  • Keyboard & wheel
  • Intl formatting
  • Spinbutton a11y
  • Form-ready

Hold + or − to speed up · Shift + ↑ for ±10

Installation

$ npx shadcn@latest add https://duskui.com/r/number-input.json

Usage

quantity.tsx
"use client"

import * as React from "react"
import { NumberInput } from "@/components/dusk/number-input/number-input"

export function Quantity() {
  const [quantity, setQuantity] = React.useState<number | null>(1)
  return (
    <NumberInput
      aria-label="Quantity"
      value={quantity}
      onValueChange={setQuantity}
      min={1}
      max={99}
    />
  )
}

Examples

Currency, percent & units

Pass any Intl.NumberFormat options with formatOptions and a locale. Typing is parsed back in that locale — try 3,75 in the German field. Values are rounded to what the field can display, so the number you get matches what you see.

In a form

With name, the raw number is submitted through a hidden input — not the formatted text. Typed values commit on blur or Enter, synchronously, so a submitting form sees them.

Between 1 and 12. Type a number and press Enter.

The form submits the raw number through a hidden input.

API Reference

Other props (placeholder, aria-*, onFocus…) go to the inner <input>. className styles the outer field (it defaults to w-36).

PropTypeDefaultDescription
value / onValueChangenumber | null / (v: number | null) => void—Controlled value; null is empty.
defaultValuenumber | nullnullUncontrolled initial value.
min / maxnumber—Limits. Values are clamped, and hitting a limit nudges the field.
stepnumber1Amount for the buttons and Arrow keys.
largeStepnumberstep × 10Amount for PageUp / PageDown and Shift + Arrow.
localestring"en-US"Locale for formatting and parsing.
formatOptionsIntl.NumberFormatOptions—Currency, percent, unit, fraction digits…
allowWheelbooleanfalseStep with the mouse wheel while focused.
size"sm" | "default" | "lg""default"Height and button size.
namestring—Submits the raw number with a hidden input.
decrementLabel / incrementLabelstring"Decrease" / "Increase"Button labels for assistive tech.
inputClassNamestring—Classes for the inner input.

Accessibility

  • A real <input inputMode="decimal"> with role="spinbutton", aria-valuenow, aria-valuemin, aria-valuemax and the formatted value in aria-valuetext.
  • Keyboard: Arrow Up / Down step, Shift + Arrow and PageUp / PageDown take large steps, Home / End jump to min / max, Enter commits typing and Escape reverts it.
  • The − / + buttons are labelled, point to the input with aria-controls, and are left out of the Tab order (the input already handles the keys), as in the WAI-ARIA spinbutton pattern.
  • The rolling digits are a visual layer; the real text stays in the input, so selection, copy and screen readers work as usual.
  • Under prefers-reduced-motion the digits cross-fade and the limit nudge is skipped.