Input Number
newFor when typing "5" is just too much effort. A number field with stepper buttons inside the frame.
Open Props in the corner of the example to try variant, size, orientation, disabled and readonly. disabled fades the frame, the text and both buttons; readonly keeps the text readable and disables the buttons. At min or max only the step that would leave the range is disabled.
The five text control variants, the same as on Input.
The field runs from 28px at xs to 48px at xl, the heights of the matching inputs. Horizontal buttons are squares inset from the frame, from 24px to 40px, with a radius concentric with the frame's; vertical buttons are as wide as those squares and split the height.
orientation="vertical" stacks both buttons at the end of the field as chevrons, half the field's height each. The text keeps to the start, where it reads as a plain input.
Installation
Usage
<script setup lang="ts">
import { InputNumber, InputNumberDecrement, InputNumberIncrement, InputNumberInput } from '@/components/ui/input-number'
const quantity = ref(1)
</script>
<template>
<InputNumber v-model="quantity" :min="0" :max="99">
<InputNumberDecrement />
<InputNumberInput aria-label="Quantity" />
<InputNumberIncrement />
</InputNumber>
</template>
InputNumber: the frame, same as InputInputNumberInput: the text box; attributes likeplaceholdergo hereInputNumberIncrement,InputNumberDecrement: the + and − buttons
The buttons go where orientation puts them, in any order. Don't need one? Leave it out.
v-model is a number, or undefined when the field is empty. The value is clamped to min and max when you leave the field or press Enter.
Buttons, arrow keys and the scroll wheel change the value by step, snapping to it unless stepSnapping is off. Hold a button to keep going.
Set name, and it submits with the form. Inside a Field, it works as usual.
Examples
Formatting
Pass Intl.NumberFormat options to formatOptions and a locale like 'de-DE' to locale.
The field shows formatted text, but v-model stays a plain number: 50% is 0.5, $12.99 is 12.99.
The format also decides what you can type: no decimals in the format, no decimal separator. Phones get the matching keyboard.
Half-kilogram steps.
Stored as a fraction.
German formatting.
In a field
Label, description and error come from the field. The label focuses the input, required marks it, and invalid turns the frame destructive.
API Reference
Every part accepts class, merged over its base classes.
InputNumber
| Prop | Default | Type and description |
|---|---|---|
| defaultValue | — | numberThe starting number when |
| modelValue | — | number | nullThe number, bound with |
| min | — | numberThe smallest value allowed. Typing below it is clamped on commit, and the decrement button disables at it. |
| max | — | numberThe largest value allowed. The increment button disables at it. |
| step | — | numberHow much a button, an arrow key or a wheel tick changes the value. |
| stepSnapping | — | booleanSnaps every value to a multiple of |
| allowInvalid | — | booleanKeeps a typed number outside |
| focusOnChange | — | booleanMoves focus to the input when a button changes the value. On by default. |
| formatOptions | — | Intl.NumberFormatOptions
|
| locale | — | stringThe locale for formatting and parsing. Defaults to the one Reka UI's |
| disabled | — | booleanDisables the input and both buttons. Also set by a disabled field. |
| readonly | — | booleanShows the value but lets the user neither type nor step. |
| disableWheelChange | — | booleanStops the mouse wheel from stepping the focused input. |
| invertWheelChange | — | booleanScrolls up to decrease and down to increase. |
| id | — | stringOverrides the |
| startingValue | — | numberThe number the first step puts in an empty field, kept within |
| asChild | — | booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it. |
| as | — | AsTag | ComponentThe element or component to render. |
| name | — | stringSubmits the number with the form under this name, through a hidden input. |
| required | — | booleanMarks the input required. Also set by a required field. |
| orientation | "horizontal" | InputNumberOrientation
|
| variant | "outline" | "outline" | "soft" | "filled" | "ghost" | "subtle"The text control look, shared with |
| size | "md" | "md" | "xs" | "sm" | "lg" | "xl"The field's height, from 28px at |
| Event | Payload and description |
|---|---|
| update:modelValue | [val: number | undefined]Fires when a button, a key, the wheel or a committed edit changes the number. |
| Slot | Scope and description |
|---|---|
| default | {}The |
InputNumberIncrement
| Prop | Default | Type and description |
|---|---|---|
| disabled | — | booleanDisables this button on its own. It is also disabled by the field, by |
| Slot | Scope and description |
|---|---|
| default | {}The icon. A plus sign by default, or a chevron up in the vertical orientation. |
InputNumberDecrement
| Prop | Default | Type and description |
|---|---|---|
| disabled | — | booleanDisables this button on its own. It is also disabled by the field, by |
| Slot | Scope and description |
|---|---|
| default | {}The icon. A minus sign by default, or a chevron down in the vertical orientation. |
InputNumberInput
No props, events, slots or exposed members.
Props
- defaultValue
numberThe starting number whenv-modelis not used.- modelValue
number | nullThe number, bound withv-model.undefinedwhile the field is empty.- min
numberThe smallest value allowed. Typing below it is clamped on commit, and the decrement button disables at it.- max
numberThe largest value allowed. The increment button disables at it.- step
numberHow much a button, an arrow key or a wheel tick changes the value.1by default.- stepSnapping
booleanSnaps every value to a multiple ofstepcounted frommin. On by default; turn it off to allow any typed value between steps.- allowInvalid
booleanKeeps a typed number outsideminandmax, or off thestepgrid, as it is instead of correcting it; the buttons, arrow keys and wheel still clamp and snap. Such a number isn't marked invalid for you: check it yourself and setaria-invalid, orinvalidon the surroundingField. Needsreka-ui2.11 or later.- focusOnChange
booleanMoves focus to the input when a button changes the value. On by default.- formatOptions
Intl.NumberFormatOptionsIntl.NumberFormatoptions for the text shown and the characters accepted: decimals, a percentage, a currency or a unit.- locale
stringThe locale for formatting and parsing. Defaults to the one Reka UI'sConfigProvidersets, or the browser's.- disabled
booleanDisables the input and both buttons. Also set by a disabled field.- readonly
booleanShows the value but lets the user neither type nor step.- disableWheelChange
booleanStops the mouse wheel from stepping the focused input.- invertWheelChange
booleanScrolls up to decrease and down to increase.- id
stringOverrides theidtaken from a surrounding field. It lands on the input, so the field's label focuses it.- startingValue
numberThe number the first step puts in an empty field, kept withinminandmaxbut not snapped tostep.minby default, or0without one. Needsreka-ui2.11 or later.- asChild
booleanRender the single child instead of a wrapper, merging the root's attributes and classes onto it.- as
AsTag | ComponentThe element or component to render.- name
stringSubmits the number with the form under this name, through a hidden input.- required
booleanMarks the input required. Also set by a required field.- orientation
"horizontal" InputNumberOrientationhorizontalputs the decrement at the start and the increment at the end of the field.verticalstacks both at the end, with chevrons.- variant
"outline" "outline" | "soft" | "filled" | "ghost" | "subtle"The text control look, shared withInput:outline,soft,filled,ghostorsubtle.- size
"md" "md" | "xs" | "sm" | "lg" | "xl"The field's height, from 28px atxsto 48px atxl; the buttons and type scale with it.
Emits
- update:modelValue
[val: number | undefined]Fires when a button, a key, the wheel or a committed edit changes the number.
Slots
- default
{}TheInputNumberInputand the stepper buttons, in any order.
Props
- disabled
booleanDisables this button on its own. It is also disabled by the field, byreadonlyand atmax.
Slots
- default
{}The icon. A plus sign by default, or a chevron up in the vertical orientation.
Props
- disabled
booleanDisables this button on its own. It is also disabled by the field, byreadonlyand atmin.
Slots
- default
{}The icon. A minus sign by default, or a chevron down in the vertical orientation.
InputNumberInput
Has no props of its own. Attributes go to the <input>, and a template ref gives the element.
Data attributes
| data-slot | Attributes | Description |
|---|---|---|
| input-number | data-orientation, data-variant, data-size, data-disabled, data-readonly | The frame, a role="group", holding the hidden form input. |
| input-number-input | data-disabled, data-readonly, aria-invalid | The text box, a role="spinbutton" with aria-valuenow, aria-valuemin and aria-valuemax. |
| input-number-increment | data-disabled, data-pressed | The button that adds a step. |
| input-number-decrement | data-disabled, data-pressed | The button that takes a step away. |
CSS variables
| Variable | Default | Description |
|---|---|---|
| --frame-radius | --radius-control-md at md | The frame's radius for its size. Buttons take this less their distance from the edge, but never less than half of it. Set --control-radius to change every control at once. |
| --control-padding | 12px | Side padding of the input where no button sits; next to a button it is 6px. |
| --input-number-align | center, start when vertical | The text alignment of the input, set on the root so that a Field or Item around it cannot change it; an alignment class such as text-start on InputNumberInput wins over it. |
| --stepper-size | 28px | The side of a horizontal button and the width of the vertical column, per size. |
| --stepper-inset | 4px | A horizontal button's distance from the frame's outer edge. |
| --stepper-icon | 16px | Icon size in horizontal buttons, per size. |
| --stepper-chevron | 14px | Icon size in vertical buttons, one step smaller. |
Keyboard
| Key | Action |
|---|---|
| ArrowUp / ArrowDown | Steps the value up or down. |
| PageUp / PageDown | Steps by ten steps. |
| Home / End | Jumps to min or max. |
| Enter | Commits the typed text, parsing and clamping it. |