NumberInput

A numeric field with increment and decrement buttons. Values are formatted with Intl.NumberFormat and typed text is parsed in the same locale, so 1.234,5 works in tr-TR and 1,234.5 in en-US.

StableSource
value: 1

Import

import { NumberInput } from "@meridui/react";

Examples

Currency, percent and units

formatOptions is passed to Intl.NumberFormat. For percent, the value is the fraction (0.15 shows as 15%).

Sizes and states

API reference

Accepts every <input> attribute except type, value, defaultValue, onChange, size, min, max and step; the ref goes to the <input>. className and style go on the wrapper. Picks up Field wiring like Input.

PropTypeDefaultDescription
valuenumber | null–Controlled value; null is empty.
defaultValuenumber | nullnullInitial value when uncontrolled.
onValueChange(value: number | null) => void–Called with the committed value (on step, Enter or blur).
min / maxnumber–Limits. Values are clamped; the matching button disables at a limit.
stepnumber1Amount added by buttons and arrow keys.
largeStepnumberstep * 10Amount added by Page Up / Page Down.
localestringruntime localeLocale for formatting and parsing.
formatOptionsIntl.NumberFormatOptions–Currency, percent, unit, fraction digits…
size"sm" | "md" | "lg""md"Height.
invalidboolean–aria-invalid and the danger border.
hideStepperbooleanfalseHide the buttons.
incrementLabelstring"Increase"Accessible name of the + button.
decrementLabelstring"Decrease"Accessible name of the − button.
namestring–Hidden input with the raw number (no formatting).

Styling

ClassElement
.mrd-number-inputWrapper (data-size, data-invalid, data-disabled)
.mrd-number-input__fieldThe <input role="spinbutton">
.mrd-number-input__stepper, .mrd-number-input__stepButton group and each button

Accessibility

The field is a role="spinbutton" with aria-valuenow, aria-valuemin, aria-valuemax and a formatted aria-valuetext. The buttons are not tab stops (tabindex="-1"): the keyboard path is the arrow keys, following the APG spinbutton pattern. Each button is at least 24×24px.

KeyAction
ArrowUpArrowDownIncrease / decrease by step.
PageUpPageDownIncrease / decrease by largeStep.
HomeEndSet to min / max (when set).
EnterCommit the typed text.
  • Slider — when an approximate value is enough.
  • Input — for free text.