Examples

Basic

Clamped to 1–20; the raw number is submitted with the form.

Preview

Up to 20 per order.

Example.tsx
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.

Preview
Example.tsx
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

NumberInput props
PropTypeDefault
label
Visible label, associated with the control.
ReactNode—
description
Help text linked with aria-describedby.
ReactNode—
error
Error message; marks the control invalid and is described.
ReactNode—
invalid
Invalid without a message.
booleanfalse
hideLabel
Keep the label for screen readers, hide it visually.
booleanfalse
showOptional
Append “(optional)” to labels of non-required fields.
booleanfalse
value / defaultValue
NaN means empty.
number—
onValueChange
Called when the value is committed (blur, Enter, step).
(value: number) => void—
minValue · maxValue · step
number—
formatOptions
Currency, percent, unit, fraction digits.
Intl.NumberFormatOptions—
showStepper
booleantrue
incrementLabel · decrementLabel
Translate these.
string'Increase' · 'Decrease'
name
Submits the unformatted number via a hidden input.
string—
required · disabled · readOnly
booleanfalse
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.

AttributeValues
[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.
Keyboard interactions
KeyAction
↑ / ↓Increment / decrement by step
Page Up / Page DownLarger step
Home / EndMinimum / maximum
EnterCommit 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.