Components

Number Input

A styled number input component with a draggable value handle.

pnpx shadcn@latest add https://blog.skxv.dev/r/number-input.json

Installation

Add the Number Input component with one command:

pnpx shadcn@latest add https://blog.skxv.dev/r/number-input.json

Usage

import { NumberInput } from "@/components/registry/number-input";

<NumberInput min={0} max={100} defaultValue={50} />;

Drag the left icon up or down to change the value. Use dragAxis="horizontal" to change values by dragging left or right. Pass icon to customize the handle, or icon={false} to render a plain input.

Forward a ref to receive the native input[type=number] for forms and imperative access.

API Reference

Extends InputHTMLAttributes<HTMLInputElement> except type.

PropTypeDefaultDescription
valuenumber | string-Controlled value. Pair with onChange.
defaultValuenumber | string-Initial value when uncontrolled.
minnumber | string-Minimum accepted value.
maxnumber | string-Maximum accepted value.
stepnumber | string-Increment used by browser steppers, keyboard changes, and drag.
iconReactNode | falsenumber iconLeft drag handle content. Pass false to disable the handle.
dragAxis"vertical" | "horizontal""vertical"Direction used for drag-to-change.
dragSensitivitynumber0.35Multiplier for how quickly dragging changes the value.
disabledbooleanfalseDisables interaction.
readOnlybooleanfalsePrevents edits while keeping the input focusable.
onChange / onInputChangeEventHandler-Standard number input handlers. event.target.value is a string.
className / stylestring / CSSProperties-Applied to the input element.

Examples

Default

Uncontrolled number input with browser number behavior and draggable handle.

Controlled

Use value and onChange for controlled state.

Horizontal Drag

Use dragAxis="horizontal" to change values by dragging left or right.

Min & Max

Pass min, max, and step for browser-level numeric constraints.

Disabled

Use disabled to disable the input.

Read Only

Use readOnly to prevent edits without removing focus styles.