Skip to content
shadcn.io
shadcn.io is not affiliated with official shadcn/ui

Shadcn Number Input for React and Tailwind

Numeric input for entering values.

Installation

bunx --bun shadcn@latest add https://kit.dev/r/number-input.json

Anatomy

NumberInput
└── NumberInputGroup
    ├── NumberInputDecrement
    ├── NumberInputInput
    ├── NumberInputIncrement
    └── NumberInputScrubber

Usage

import { 
  NumberInput, 
  NumberInputGroup, 
  NumberInputInput, 
  NumberInputIncrement, 
  NumberInputDecrement 
} from "@/comopnents/ui/number-input";
<NumberInput>
  <NumberInputGroup>
    <NumberInputInput />
    <NumberInputIncrement />
    <NumberInputDecrement />
  </NumberInputGroup>
</NumberInput>

Controlled

Use value and onValueChange to control the number input. Keep the value as a string when using formatOptions to preserve locale formatting.

States

Disabled

Use the disabled prop to disable the number input.

Invalid

Use the invalid prop to mark the number input as invalid.

Sizes

Use the size prop to change the input height.

Small

Medium

Large

Examples

Field Only

With Field

Use Field components for a labeled number input with helper text.

With Input Group

Use InputGroup, InputGroupAddon, and InputGroupText to add prefix or suffix.

With Scrub

Use the NumberInputScrubber to drag the label to change the value.

With Range

Pass min and max to restrict the value to the specified range.

Use clampValueOnBlur={false} to allow typing outside range until blur.

With Formatted Value

Use formatOptions with Intl.NumberFormatOptions to format the displayed value.

With Step

Use the step prop to set the increment/decrement amount.

Mouse Wheel

Use the allowMouseWheel prop to increment or decrement the value with the mouse wheel.

API Reference

NumberInput

Root component. Manages numeric value and stepper controls.

PropTypeDefault
size"sm" | "md" | "lg""md"
scrubberbooleanfalse
defaultValuestring-
valuestring-
minnumberNumber.MIN_SAFE_INTEGER
maxnumberNumber.MAX_SAFE_INTEGER
stepnumber1
formatOptionsIntl.NumberFormatOptions-
disabledboolean-
invalidboolean-
focusInputOnChangebooleantrue
clampValueOnBlurbooleantrue
allowMouseWheelbooleanfalse
onValueChange(details: ValueChangeDetails) => void-
classNamestring-
asChildbooleanfalse

NumberInputGroup

Wraps the input and increment/decrement buttons.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputDecrement

Decreases the value by the step amount.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputIncrement

Increases the value by the step amount.

PropTypeDefault
classNamestring-
asChildbooleanfalse

NumberInputInput

Numeric input. Accepts number or direct typing.

PropTypeDefault
size"sm" | "md" | "lg""md"
classNamestring-
asChildbooleanfalse

NumberInputScrubber

Drag area for scrubbing the value.

PropTypeDefault
classNamestring-
asChildbooleanfalse

For a complete list of props, see the Ark UI documentation.