Loading component…
Loading component…
A field for one number
To reuse this local React demo, copy all files from the Code tab into the same folder, then import NumberInput from ./number-input.
import { useState } from "react";
import { NumberInput } from "@/components/ui/number-input";
export function RunLimits() {
const [tokens, setTokens] = useState<number | null>(32000);
return (
<form className="grid gap-4">
<NumberInput
label="Max tokens per run"
unit="tokens"
value={tokens}
onValueChange={setTokens}
min={1000}
max={200000}
step={1000}
hint="The answer stops here."
/>
<NumberInput
label="Budget per run"
name="budget"
prefix="$"
defaultValue={25}
min={0}
max={100}
step={5}
formatOptions={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }}
/>
</form>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| value | number \| null | The number; null is an empty field. Use it with onValueChange to control the field | |
| defaultValue | number \| null | null | The starting number when the field keeps its own value |
| onValueChange | (value: number \| null) => void | Called after every step, and when typing is done (blur or Enter) – with the clamped number, or null when emptied | |
| min | number | The lowest value: typing less is raised to it, − and Home stop there | |
| max | number | The highest value: typing more is lowered to it, + and End stop there | |
| step | number | 1 | What − / + and the arrow keys add or take away; steps land on multiples of it (counted from min) |
| largeStep | number | step × 10 | What Page Up / Page Down add or take away |
| unit | ReactNode | Quiet text right after the value – "tokens", "%", "ms"; read out with the value | |
| prefix | ReactNode | Quiet text or a 16px icon before the value – e.g. "$" | |
| locale | string | the browser's | Shows and reads the number in this locale – 4,000 in en-US, 4.000 in de-DE; typing follows the same separators |
| formatOptions | Intl.NumberFormatOptions | How the value is shown once you leave the field, e.g. { maximumFractionDigits: 2 } or { style: "percent" } (then 0.25 shows 25%) | |
| label | ReactNode | Shown above the field; clicking it focuses the input | |
| hint | ReactNode | A quiet line under the field – the error takes its place while there is one | |
| error | ReactNode | Marks the field invalid (red edge, aria-invalid) and shows the message where the hint was | |
| optional | boolean | false | Adds "Optional" next to the label |
| size | "sm" \| "md" \| "lg" | "md" | 32 · 36 · 40px high; taller on touch screens |
| name | string | Sends the plain number (4000, not "4,000") with the form, through a hidden input | |
| inputClassName | string | Extra class on the input itself | |
| ...input props | ComponentProps<"input"> | placeholder, disabled, readOnly, required, onBlur, onKeyDown, aria-label, ref and the rest go to the input |
Fills its container; the value hugs its text so the unit sits right after it, and − / + keep their place at the end
Very long numbers fit to the field and are cut with an ellipsis before the buttons move
Touch screens get taller fields, 32px buttons with a larger hit area and 16px text, so iOS doesn't zoom in
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
@import "tailwindcss"; in your main CSS file.