Forms
NumberInput
A locale-aware numeric field: formats and parses with Intl.NumberFormat (currency, percent, units), clamps to a range and steps with the keyboard or stepper buttons.
import { NumberInput } from '@reactloom/ui';Examples
Basic
Clamped to 1–20; the raw number is submitted with the form.
Up to 20 per order.
import { NumberInput } from '@reactloom/ui';
export default function Example() {
return (
<div style={{ width: '100%', maxWidth: 240 }}>
<NumberInput label="Quantity" name="quantity" defaultValue={1} minValue={1} maxValue={20} description="Up to 20 per order." />
</div>
);
}Formats and locales
Wrap part of the tree in LocaleProvider to change the locale.
import { LocaleProvider, NumberInput, Stack } from '@reactloom/ui';
export default function Example() {
return (
<Stack gap="4" style={{ width: '100%', maxWidth: 280 }}>
<NumberInput label="Budget" defaultValue={1250} step={50} formatOptions={{ style: 'currency', currency: 'USD' }} />
<NumberInput label="Discount" defaultValue={0.15} step={0.05} minValue={0} maxValue={1} formatOptions={{ style: 'percent' }} />
<NumberInput label="Distance" defaultValue={12.5} step={0.5} formatOptions={{ style: 'unit', unit: 'kilometer' }} />
{/* Locale comes from the nearest LocaleProvider (or the browser). */}
<LocaleProvider locale="de-DE">
<NumberInput label="Preis" defaultValue={1234.5} formatOptions={{ style: 'currency', currency: 'EUR' }} />
</LocaleProvider>
</Stack>
);
}API reference
| Prop | Type | Default |
|---|---|---|
labelVisible label, associated with the control. | ReactNode | — |
descriptionHelp text linked with aria-describedby. | ReactNode | — |
errorError message; marks the control invalid and is described. | ReactNode | — |
invalidInvalid without a message. | boolean | false |
hideLabelKeep the label for screen readers, hide it visually. | boolean | false |
showOptionalAppend “(optional)” to labels of non-required fields. | boolean | false |
value / defaultValueNaN means empty. | number | — |
onValueChangeCalled when the value is committed (blur, Enter, step). | (value: number) => void | — |
minValue · maxValue · step | number | — |
formatOptionsCurrency, percent, unit, fraction digits. | Intl.NumberFormatOptions | — |
showStepper | boolean | true |
incrementLabel · decrementLabelTranslate these. | string | 'Increase' · 'Decrease' |
nameSubmits the unformatted number via a hidden input. | string | — |
required · disabled · readOnly | boolean | false |
size | 'sm' | 'md' | 'lg' | 'md' |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-disabled] | present when on |
[data-invalid] | present when on |
[data-position] | present when on |
[data-readonly] | present when on |
[data-size] | sm · md · lg |
Theme tokens it reads
--pl-color-bg-muted --pl-color-bg-subtle --pl-color-bg-surface --pl-color-border-default --pl-color-border-focus --pl-color-border-input --pl-color-danger-border --pl-color-fg-default --pl-color-fg-disabled --pl-color-fg-muted --pl-control-height-lg --pl-control-height-md --pl-control-height-sm --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-lg --pl-font-size-md --pl-font-size-sm --pl-radius-md --pl-shadow-xs
Accessibility
- The input keeps role textbox with a numeric inputMode, so mobile keyboards and screen readers treat it as editable text; values are announced formatted.
- Stepper buttons are excluded from the Tab order (the arrow keys do the same job) but remain clickable.
- Typing is validated against the locale, so only characters that can form a number are accepted.
| Key | Action |
|---|---|
| ↑ / ↓ | Increment / decrement by step |
| Page Up / Page Down | Larger step |
| Home / End | Minimum / maximum |
| Enter | Commit the typed value |
Usage guidelines
Do
- Use for quantities and amounts people type or adjust in small steps.
Don’t
- Don’t use for identifiers like phone or card numbers — use Input.
- Don’t format numbers yourself — pass formatOptions so parsing matches.