Input Number

new

For when typing "5" is just too much effort. A number field with stepper buttons inside the frame.

Demo

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 Input
  • InputNumberInput: the text box; attributes like placeholder go here
  • InputNumberIncrement, 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.

Formatting

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.

In a field
Up to eight guests per booking.

API Reference

Every part accepts class, merged over its base classes.

InputNumberInput

Has no props of its own. Attributes go to the <input>, and a template ref gives the element.

Data attributes

data-slotAttributesDescription
input-numberdata-orientation, data-variant, data-size, data-disabled, data-readonlyThe frame, a role="group", holding the hidden form input.
input-number-inputdata-disabled, data-readonly, aria-invalidThe text box, a role="spinbutton" with aria-valuenow, aria-valuemin and aria-valuemax.
input-number-incrementdata-disabled, data-pressedThe button that adds a step.
input-number-decrementdata-disabled, data-pressedThe button that takes a step away.

CSS variables

VariableDefaultDescription
--frame-radius--radius-control-md at mdThe 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-padding12pxSide padding of the input where no button sits; next to a button it is 6px.
--input-number-aligncenter, start when verticalThe 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-size28pxThe side of a horizontal button and the width of the vertical column, per size.
--stepper-inset4pxA horizontal button's distance from the frame's outer edge.
--stepper-icon16pxIcon size in horizontal buttons, per size.
--stepper-chevron14pxIcon size in vertical buttons, one step smaller.

Keyboard

KeyAction
ArrowUp / ArrowDownSteps the value up or down.
PageUp / PageDownSteps by ten steps.
Home / EndJumps to min or max.
EnterCommits the typed text, parsing and clamping it.

Changelog

  1. registry 0.24.1

    35a5371 — No component styles an element through a :has() on its parent or group any more. Chrome restyles the whole subtree of every :has() anchor above a node that is added or removed, once some rule puts :has() away from the element it styles: a page wrapped in one such anchor recalculated every element for each list row it mounted. The Dialog, Drawer and Tour headers, the InputGroup and InputNumber insets, the Combobox clear button, the InputFloating notch, a FieldLabel beside a disabled checkbox or radio, the Rating ring, and the Slider and ScrollArea examples now read their neighbours with ~ or a :has() on the element itself. The InputGroup addons fade through a variable that the group sets. FileUpload, Image, Marquee and DataTable mark the state on an element instead: the hidden input's focus, an ImageError inside, keyboard focus, and the body above pinned bottom rows. scripts/has-selectors.test.ts keeps the pattern out.

    useSwipeSnap no longer flushes styles for an instant move that leaves the offset where it is, such as new points at rest.

  2. core 0.17.1

    35a5371 — No component styles an element through a :has() on its parent or group any more. Chrome restyles the whole subtree of every :has() anchor above a node that is added or removed, once some rule puts :has() away from the element it styles: a page wrapped in one such anchor recalculated every element for each list row it mounted. The Dialog, Drawer and Tour headers, the InputGroup and InputNumber insets, the Combobox clear button, the InputFloating notch, a FieldLabel beside a disabled checkbox or radio, the Rating ring, and the Slider and ScrollArea examples now read their neighbours with ~ or a :has() on the element itself. The InputGroup addons fade through a variable that the group sets. FileUpload, Image, Marquee and DataTable mark the state on an element instead: the hidden input's focus, an ImageError inside, keyboard focus, and the body above pinned bottom rows. scripts/has-selectors.test.ts keeps the pattern out.

    useSwipeSnap no longer flushes styles for an instant move that leaves the offset where it is, such as new points at rest.

  3. registry 0.22.0

    fbe99ae — InputNumber takes its text alignment from its own root through --input-number-align: a vertical InputNumber in a horizontal Field is no longer centred, an alignment class such as text-start on InputNumberInput wins, and a vertical decrement keeps its corner inside a filled Item.

  4. registry 0.21.0

    95a0fa1 — Parts follow their root's size through CSS variables instead of the context, so a class on a part wins over the size. PinInput sets --pin-input-slot, TagsInput --tags-input-line and --tags-input-delete, and PinInput, InputNumber, TagsInput and InputGroup set --control-text and --control-text-leading for the field inside (textControlText and textControlInnerText in @/ui/input). NavigationMenu's triggers and links read the --nav-* variables of the menu instead of setting their own, and DataTable's sort buttons and row toggles shrink at xs through the table's variables. PinInput's slots now sit --control-gap-* apart (2px wider at sm, lg and xl); nothing else moves. inputNumberInputVariants, tagsInputInputVariants and tagsInputItemDeleteVariants became the strings inputNumberInput, tagsInputInput and tagsInputItemDelete, inputGroupControlText is gone, and pinInputSlotVariants lost its size key.

  5. registry 0.18.0

    779955e — Corners come in three roles: rounded-control-*, rounded-surface-* and rounded-item-*, each scaled from --radius and tunable on its own with --control-radius, --surface-radius and --item-radius, on :root or any element. Every component uses them, and cn() merges them, so a class prop still wins.

    - --control-radius was the Input family's frame variable. It now sets every control, and the frames use --frame-radius. - Nested parts no longer turn square at small radii: the InputGroup button, the InputNumber steppers, the TagsInput chips, the DatePicker trigger and the Toast and Tour close buttons. - Menus, lists, pill tabs, the menubar and the toolbar wrap their corners around their items. Pill tabs are rounder (12/8px at md instead of 8/4px), menus and lists grow by up to 2px, and their rows at sizes xs and xl follow their height. Item sm takes 8px instead of 6.4px.

  6. registry 0.12.0

    c79028b — The control scale is now a set of tokens: --control-height-*, --control-padding-*, --control-icon-* and --control-gap-* for xs to xl, added to :root by the tokens item. Button, Input, InputFloating, Select, Combobox, InputNumber, TagsInput, PinInput, InputTime, InputGroup, Menu, Tabs, ColorPicker and Pagination read them, so overriding one on :root resizes every control of that size.

    Some sizes that strayed from the scale now follow it. Button icons are 20px at lg and xl instead of 16px, and so are the icons of Toggle, ToggleGroup, Toolbar and Pagination at those sizes. The gap between an icon and its label is 6, 8, 8, 10 and 12px from xs to xl, about half the icon, everywhere that has one: Button and the components built on it (where it was 4, 6, 8, 8 and 8px), Menu items and the Select, Combobox and Command lists (8, 10, 12, 12 and 12px), and Tabs triggers (6, 8, 8, 8 and 10px). Inset and checkbox or radio items move their labels with it, so they stay in line with items that have an icon. Everything else keeps its size.

  7. registry 0.11.0

    The text control frame of InputGroup, InputNumber, TagsInput and the Combobox anchor ignores what sits in an InputGroupAddon: a disabled checkbox's hidden form input no longer greys the frame or fades the addons, and the browser focusing it after a failed submit no longer lights the frame. A focused control that fails native validation shows the destructive edge again instead of the focus one.

  8. registry 0.10.0

    e03458c — The text control frame of InputGroup, InputNumber, TagsInput and the Combobox anchor reads focus, invalid and disabled from any input, textarea or role="spinbutton" inside it, not only from a direct child. An InputGroupAddon click focuses the first segment of a segmented control, and addons fade when any input inside the group is disabled.

  9. registry 0.9.0

    0c326fd — New InputNumber: a number field over Reka UI's NumberField with InputNumberInput, InputNumberIncrement and InputNumberDecrement parts inside one frame, in Input's variants and sizes, horizontal or vertical, with min, max, step, formatOptions and locale, wired to a surrounding Field.

    Input now exports textControlFrameVariant, the text control variants for a frame around a control, read from the control's focus, invalid and disabled state. InputGroup draws its frame from it; its radius variable is renamed from --input-group-radius to --control-radius.