Skip to content
GetUrUI

Number Input

New
.md

Number field with steppers on both sides or stacked on the right, min/max/step, full keyboard control and press-and-hold that speeds up; digits roll to each new value on a spring.

numberstepperspinbuttonquantityinputformcounter

Installation

$npx shadcn@latest add @geturui/number-input
Download source (.zip)

Also installs: Field

Usage

usage.tsx
1import * as React from "react";
2import { NumberInput } from "@/components/ui/number-input";
3
4export function Seats() {
5  const [seats, setSeats] = React.useState<number | null>(5);
6  return <NumberInput label="Seats" value={seats} onValueChange={setSeats} min={1} max={250} unit="seats" />;
7}

Props

PropTypeDefaultDescription
valuenumber | null—Value when controlled. null means empty.
defaultValuenumber | nullnullInitial value when uncontrolled.
onValueChange(value: number | null) => void—Called on every step, key press or committed edit.
min / maxnumber—Bounds. Values clamp on commit and the matching stepper disables at the edge.
stepnumber1Amount per arrow press or stepper tap; its decimals set the precision.
largeStepnumberstep × 10Amount for PageUp/PageDown and Shift+Arrow.
orientation"horizontal" | "vertical""horizontal"Minus/plus on both sides, or chevrons stacked on the right.
size"sm" | "md" | "lg""md"32, 40 or 48px, matching Button.
unitstring—Unit shown after the value and read out with it.
formatOptionsIntl.NumberFormatOptions—Formatting, e.g. currency or percent.
localestring"en-US"Formatting locale. Fixed by default so server and client agree.
label / hint / errorReactNode—Field label, helper line and error message.

Accessibility

  • The input has role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and aria-valuetext including the unit.
  • Arrow Up/Down step, Shift or PageUp/PageDown take large steps, Home/End jump to min/max, Escape cancels a typed edit and Enter commits it.
  • Steppers are labelled buttons kept out of the tab order (the keyboard already covers them); the rolling digits are aria-hidden and snap when reduced motion is on.

Related