Quantity Input
betaA number with a unit: step it, switch between kg and lb or GB and TB with the amount converted, or type "5 lb".
- Forms
- 3 files
- 1 npm package
- Accessibility notes
pnpm dlx @dowel-ui/cli add quantity-inputnpm packages installed: class-variance-authority.
import { QuantityInput } from "@/components/ui/quantity-input";Default
Storage Size
Temperature
Duration
German Locale
<QuantityInput>
| Prop | Type | Default |
|---|---|---|
units (required)The units offered, all of one dimension. The first is the default. | readonly QuantityUnit[] | — |
convertOnUnitChangeConverts the amount when the unit changes (5 kg → 11.02 lb). Off, the number stays. | boolean | true |
defaultValueInitial value when uncontrolled. Defaults to 0 in the first unit, within the bounds. | Quantity | — |
disabled | boolean | false |
inputRefRef to the text field, for focusing it. A form library's field ref goes here. | Ref<HTMLInputElement> | — |
inputSize | "sm" | "md" | "lg" | "md" |
labelVisible label, linked to the field. Without it, pass aria-label or aria-labelledby. | ReactNode | — |
labelsReplaces any of the field's own copy. | Partial<QuantityInputLabels> | — |
largeStepSteps taken by Shift+Arrow and Page Up/Down. | number | 10 |
localeLocale for writing and reading numbers. Defaults to the browser's, used once hydrated: the server and hydration write en-US, so the two agree. | string | — |
maxHighest quantity, in any of the units. | Quantity | — |
minLowest quantity, in any of the units. It follows the field into whichever unit is chosen. | Quantity | — |
nameSubmits the amount under this name, as a plain number ("11.02"). | string | — |
onValueChangeCalled with each committed change: a step, a unit change, or typed text on blur or Enter. | (value: Quantity) => void | — |
readOnly | boolean | false |
stepStep for every unit. Leave unset to use each unit's own step, or 1. | number | — |
unitNameSubmits the unit's value under this name. Defaults to | string | — |
valueControlled value. | Quantity | — |
Plus every attribute of <div> except defaultValue, onChange, children.
10/10
checks passed
- Tested — passes
- axe assertion — passes
- Keyboard tested — passes
- Storybook examples — passes
- Accessibility documented — passes
- Semantic tokens only — passes
- Motion from tokens — passes
- className merged — passes
- Visible focus — passes
- No fixed widths — passes