Overview
Get Started
Components
- Accordion
- Alert Dialog
- Alert
- Autocomplete
- Avatar
- Badge
- Button Group
- Button
- Calendar
- Checkbox Group
- Checkbox
- Collapsible
- Combobox
- Command
- Dialog
- Field
- Form
- Input Group
- Input
- Kbd
- Label
- Menu
- Meter
- Navigation Menu
- Number Field
- Number InputNew
- OTP Field
- Pagination
- Popover
- Radio Group
- Scroll Area
- Select
- Sheet
- Sidebar
- Slider
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Tooltip
Number Input
A compact numeric input with stacked increment and decrement buttons.
import { NumberInput } from "@/components/ui/number-input";
export function NumberInputDemo() {
return (
<div>
<label htmlFor="number-input" className="mb-2 inline-block font-medium">
Number Input
</label>
<NumberInput id="number-input" placeholder="Enter a number" />
</div>
);
}Installation
pnpm dlx @zbmui/cli@latest add number-input
Usage
import { NumberInput } from "@/components/ui/number-input";<NumberInput />Example
Sizes
Pass the size prop to set the size of the NumberInput. Available sizes are xs, sm, default, lg, and xl.
import { NumberInput } from "@/components/ui/number-input";
export function NumberInputDemo() {
return (
<div className="flex flex-col gap-4">
<NumberInput placeholder="Enter a number" size="xs" />
<NumberInput placeholder="Enter a number" size="sm" />
<NumberInput placeholder="Enter a number" size="default" />
<NumberInput placeholder="Enter a number" size="lg" />
<NumberInput placeholder="Enter a number" size="xl" />
</div>
);
}Controlled
Use value and onValueChange to control the input from state. The value is null when the input is empty.
Your age is: null
"use client";
import { useState } from "react";
import { NumberInput } from "@/components/ui/number-input";
export function NumberInputDemo() {
const [age, setAge] = useState<number | null>(null);
return (
<div>
<label htmlFor="age" className="mb-2 inline-block font-medium">
Enter your age
</label>
<NumberInput id="age" min={0} max={200} value={age} onValueChange={setAge} />
<p className="mt-2 text-muted-foreground text-sm">Your age is: {age ?? "null"}</p>
</div>
);
}Minimum and maximum value
Pass the min prop or max prop to set an upper and lower limit for the input. By default, the input will restrict the value to stay within the specified range.
function NumberInputDemo() {
return <NumberInput min={0} max={10} />;
}API Reference
NumberInput Props
Component type props
Prop
Type
Default
Expand prop details
The size of the input component.
Type
'xs' | 'sm' | 'default' | 'lg' | 'xl'Default
'default'The placeholder text to display when the input is empty.
Type
stringProps forwarded to the underlying input element, including its className.
Type
React.ComponentProps<typeof NumberField.Input>