Skip to content

React Number Input

A glass React number input with steppers you can hold, a scrub label you can drag, and Intl formatting for currency, percentages and units.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/number-field.json

Concert tickets

$24 each, up to 10 per order.

Total: $24

Files to copy

5 folders · 7 files · 4 packages
From theme/src/
  • components/number-field/
  • hooks/{use-latest.ts, use-media-query.ts, use-preferences.ts}
  • motion/tokens.ts
  • lib/{cn.ts, field-size.ts, form.ts}
  • styles/
shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/number-field.jsonRegistry item: number-field. The styles need the Tailwind v4 glass UI setup.
The examples also use
  • components/button/
  • components/spinner/
  • hooks/use-magnetic.ts
  • motion/gate.ts
  • lib/state-light.tsx
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
Packages
pnpm add @base-ui/react clsx motion tailwind-merge

Steppers

Hold a button to repeat. Arrow keys step by 1, Shift by 10; Home and End jump to the limits. The buttons switch off at min and max. Reset sets the value from outside, and the digits still roll the right way.

Up to 20 per order.

Value: 2

Formatting

Pass any Intl.NumberFormat options. Typing is parsed back in the same format and locale.

Scrub and validation

With scrub, drag the label sideways to change the value (the pointer is captured, so you can keep dragging). Errors are linked to the input and announced politely when they appear.

The room seats 10 people at most.

Props

PropTypeDefaultDescription
aria-describedbystringNoneId of extra describing text, merged with the description and error.
aria-invalidboolean | "true" | "false"NoneMarks the input invalid without an error message.
aria-labelstringNoneName for screen readers when there is no visible label.
onBlurFocusEventHandler<HTMLInputElement>NoneCalled when the input loses focus (react-hook-form: marks the field touched).
onValueChange((value: number | null, eventDetails: BaseNumberField.Root.ChangeEventDetails) => void)NoneCalled with the new value (null when cleared). Base UI's change details come second.
labelReactNodeNoneText above the field, linked to the input as its accessible name.
descriptionReactNodeNoneMuted helper text under the field.
errorReactNodeNoneError message; marks the field invalid and is announced politely to screen readers when it appears.
steppers"none" | "split" | "stacked""split"Where the − / + buttons go: "split" (default), "stacked" or "none". "stacked" falls back to "split" on touch screens (bigger targets).
scrubbooleanfalseDrag the label sideways to change the value.
animatedbooleantrueSlide changed digits when the value steps. Off with reduced motion.
sizeFieldSize"md"Height, consistent across every form control: "sm" 32px, "md" 40px, "lg" 48px (sm and md are 44px on touch screens), the same scale as Button.
placeholderstringNoneHint shown while the field is empty.
labelsPartial<NumberFieldLabels>defaultNumberFieldLabelsEvery string, for translation: { increment: "Increase", decrement: "Decrease" } (accessible names of the + and − buttons). Every other string, for translation: labels={{ increment: "…" }}; omitted keys keep the English of defaultNumberFieldLabels. All 2 keys of NumberFieldLabels are listed in the key table under the props table.
classNamestringNoneClass for the outer wrapper (label + field + messages).
inputClassNamestringNoneAdds extra classes to the native <input>.
...propsBase UI propsNoneEvery other prop of Base UI's NumberField.Root is passed through, for example form, id, inputRef, allowOutOfRange, allowWheelScrub and snapOnStep.
NumberFieldLabels keys and English defaults (2)
Pass any key in labels; the rest keep the defaults of defaultNumberFieldLabels.
KeyEnglish default
incrementIncrease
decrementDecrease

Keyboard

KeysAction
Tab/Shift + TabFocus the input; the - and + buttons are not tab stops.
Arrow Up/Arrow DownStep the value (Shift: large step, Alt: small step).
Home/EndJump to min or max.
Type, paste, clearWork as in any text field; the typed value is committed when the field loses focus.

Accessibility

  • A text input with inputmode and aria-roledescription="Number field"; the - and + buttons are named by labels.decrement and labels.increment.
  • An error is announced politely. Buttons are 44 px targets on touch screens.
  • The odometer motion is decorative; under reduced motion digits change in place.

All exports on this page

  • NumberField — A glass number field on Base UI's NumberField, for quantities, prices and settings where people nudge a number or type an exact one.
  • defaultNumberFieldLabels — The English NumberFieldLabels used when labels is omitted; a partial labels prop is merged over it.

When to use the number field

  • Use it as a number stepper for a quantity picker in a cart or a guest count on a booking form, where the minus and plus buttons repeat while held and min and max clamp the value.
  • Use it for a price or percentage input that must show currency formatting: the format prop takes Intl.NumberFormat options, and typed text is parsed back in the same locale format.
  • Use it in a settings panel or design tool where scrub lets people drag the label sideways to change the value, like the numeric fields of an editor.
  • Skip it when a rough value on a scale is enough, such as volume or opacity; a Slider fits that better, and plain Input fits free text like a postal code or a phone number.
  • Pair it with its description and error props for helper text and the message, SegmentedControl for a unit switch beside the number, and Button for an apply action after editing several values.

Frequently asked questions

67 components pages in all: browse them on All components.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .