Examples
Whole number
Use the browser's native spinbutton with an explicit range and an accessible name.
Whole number input
import { InputNumber } from "@phuctech/ui/components/input-number";
export function Example() {
return <InputNumber aria-label="Seats" min={1} max={100} step={1} defaultValue={5} />;
}
Decimal step
The native step controls precision; the public value stays a JavaScript number.
Decimal number input
import { InputNumber } from "@phuctech/ui/components/input-number";
export function Example() {
return <InputNumber aria-label="Unit price" min={0} step={0.01} defaultValue={19.95} />;
}
Invalid, read-only, and disabled
Use native constraints and field validation to explain values that cannot be changed.
Invalid, read-only, and disabled numeric inputs
import { InputNumber } from "@phuctech/ui/components/input-number";
export function Example() {
return (
<div className="grid w-full gap-3 sm:grid-cols-3">
<InputNumber aria-label="Invalid quantity" value={-1} min={0} aria-invalid="true" readOnly />
<InputNumber aria-label="Read-only quantity" value={5} readOnly />
<InputNumber aria-label="Unavailable quantity" value={5} disabled />
</div>
);
}
Try the props
Change the native step and disabled state while keeping the current numeric value in feature state.
Current value: 12
InputNumber property playground
"use client";
import { useState } from "react";
import { InputNumber } from "@phuctech/ui/components/input-number";
export function Example() {
const [value, setValue] = useState<number | null>(12);
return (
<InputNumber
aria-label="Amount"
min={0}
max={100}
step={0.5}
value={value}
onValueChange={setValue}
/>
);
}When to use
Use InputNumber for a value whose application contract is a JavaScript number, such as a count, quantity, or amount. Use Input when the entered characters themselves are the value, such as an identifier that may contain leading zeroes.
Usage
import { InputNumber } from "@phuctech/ui/components/input-number";
<InputNumber aria-label="Seats" min={1} max={100} step={1} defaultValue={5} />For controlled use, pass value and update it from onValueChange. The callback receives a finite number or null when the input is cleared. Business rules and any display formatting stay in the feature.
API
Tokens
Accessibility
InputNumber renders the native spinbutton semantics and preserves browser keyboard behavior. Provide a visible FieldLabel or an accessible name. Native min, max, step, disabled, readOnly, required, and aria-invalid are forwarded to the input.
Do and don’t
Choose a step that matches the precision the feature accepts, and validate the final value in the feature.
Use a number input for values where leading zeroes, separators, or exact decimal strings are meaningful.