Web · Components
NumberInput
Input that accepts only numbers and formats them in the locale's format while typing.
3 exports
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Quantity picker: integer, 1–99, speeds up when held
Price: two fixed decimals, no minus
₺
Percentage: show an error instead of clamping
%
Controlled usage
$
Value: 2500
Languages: same value, different separators
tr-TR
en-US
de-DE
fr-FR
en-IN
Import
Input that accepts only numbers and formats them in the locale's format while typing. Looks the same as Input; gives the value as a number.
- Format: Thousands separators are added automatically while typing (
tr-TR:1.234.567,89); the caret stays in place. Deleting over a separator deletes the digit next to it. - Numbers only: Letters and other symbols can't be typed. Both
,and.keys work for the decimal. The minus sign can be typed anywhere and toggles the sign (it can't be typed ifminis 0 or more). - Pasting: Texts like
₺1.234,56,1,234.56,1 234,5,(1.234)are converted to the right number; currency symbols and spaces are dropped. SeeparseNumber. - Keyboard: ↑/↓ change by
step, 10 times with Shift or PageUp/PageDown. Enter and blur clamp the value to the bounds and complete the format (12,→12). - Mobile: A number keyboard opens (without decimals if
decimals={0}). The iOS number keyboard has no minus key; if negative values are needed usestepperorinputMode="text". - Form: With
name, the value entersFormDatawithout separators, with a dot ("1234.56"); read it on the server withNumber().required,min,maxandstepare checked by browser validation; it returns to the initial value when the form is reset.
For use with a label, description and error message, see NumberField.
Examples
parseNumber
functionParses number text the user typed or pasted. Currencies, spaces and letters are dropped; non-Latin digits are understood.
The decimal separator is found like this:
- If the text has both
.and,, the last one is the decimal (1.234,56,1,234.56). - If a single kind of separator appears more than once, it is the group separator (
1.000.000). - If it appears once: it is the decimal if it is the locale's decimal separator; otherwise it is the group separator when exactly three digits follow (
1.234→ 1234 intr-TR), else the decimal (12.5→ 12.5).
Examples
NumberInputProps
interfaceProps of the NumberInput component.
Extends: Omit<ComponentProps<"input">, "value" | "defaultValue" | "onChange" | "type" | "min" | "max" | "step" | "children" | "prefix">
| Name | Type | Default | Description |
|---|---|---|---|
variant? | FieldVariant | CustomVariant<"field"> | Appearance: outline (bordered), filled, underline or ghost (plain). If omitted, the setting of the nearest data-field-variant container is used, or outline if there is none. See FieldVariant. | |
effect? | EffectProp | Effect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). If omitted, UIProvider appearance.defaults.field.effect. See BuiltinEffect. | |
value? | number | null | Value when controlled; null for an empty field. | |
defaultValue? | number | null | Initial value when uncontrolled. | |
onValueChange? | (value: number | null) => void | Called when the value changes: on every key while typing, on the step buttons and on blur (when clamped to the bounds). null if the field is empty. | |
min? | number | Minimum value. If it is 0 or more, a minus sign can't be typed. | |
max? | number | Maximum value. | |
step? | number | 1 | Amount changed by the ↑/↓ keys and step buttons. 10 times with Shift or PageUp/PageDown. If given, browser validation also requires the value to match this step (stepMismatch). |
decimals? | number | Maximum decimal places. If 0, only integers can be typed and on mobile a digit keyboard without a decimal key opens. If omitted, up to 10 decimal places are accepted. | |
fixedDecimals? | boolean | false | Always show decimals with decimals places (12 → 12,00). For money amounts. |
grouping? | boolean | true | Show the thousands separator (1.234.567)? |
clamp? | boolean | true | Clamp a value outside min/max to the bound on blur? If false, the value is left and browser validation gives a rangeUnderflow / rangeOverflow error. |
stepper? | boolean | false | Show − and + buttons at the end? Holding repeats with acceleration. |
locale? | string | Locale of the separators (BCP 47). @defaultValue UIProvider's locale ("tr-TR") | |
icon? | IconProp | Icon at the start of the field: a name ("money") or an element. | |
iconEnd? | IconProp | Icon at the end of the field: a name or an element. | |
prefix? | ReactNode | Short text before the number (e.g. "₺", "$"). Not part of the value or FormData. | |
suffix? | ReactNode | Unit after the number (e.g. "kg", "%", "TL"). Not part of the value or FormData. |