Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Number Input

ProNew

A number field with steppers that repeat while held, arrow-key stepping, locale formatting and a label you can drag to scrub.

Installation

pnpm dlx shadcn@latest add @viewport/number-input

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

PropTypeDefault
valuenumber | null—
defaultValuenumber | nullnull
onValueChange(value: number | null) => void—
minnumber—
maxnumber—
stepnumber

The amount one press, arrow key or scrub step changes the value by. Shift multiplies it by ten.

1
formatIntl.NumberFormatOptions

How the value is shown while the field is not being edited, e.g. `{ style: "currency", currency: "USD" }`.

—
localestring—
scrubLabelReact.ReactNode

A short label at the start of the field that can be dragged sideways to change the value, e.g. "W".

—
suffixReact.ReactNode

A unit shown after the number, e.g. "px". Not part of the value.

—

Accessibility

  • A spinbutton with min, max, current value and a formatted value text.
  • Arrow keys step, Shift steps by ten, Page Up and Down, Home and End.
  • Clamps when you leave the field, not while you type.
  • The stepper buttons are skipped by Tab; the keyboard uses the field.