shadcn.io is an independent project built on shadcn/ui
Components
Free
Number Input for Vue
A field for one number, with step buttons, limits it stays inside, and currency or percent formatting. For quantities and prices in Vue on Ark UI.
On this page9 sections
UI library: Ark UI
A number input is a text field for one number, with buttons that step it up and down and limits it won't leave. Reach for it when the number has a minimum, a maximum or a natural step: a cart quantity, a price, a percentage.
A postal code or a card number is a string of digits, not a quantity, so it belongs in an Input. When people pick a value by feel rather than type an exact one, a Slider is quicker.
Installation
Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.
The input has the spinbutton role with aria-valuenow, aria-valuemin and aria-valuemax, so a screen reader announces the number and its limits, and the keys below change it. The step buttons are labeled and left out of the tab order, since the keys do their job. The name is yours to give: inside a Field, Ark UI ties the FieldLabel to the input, as in With field.
KeyAction
Arrow Up
Increments the value of the number input by a predefined step.
Arrow Down
Decrements the value of the number input by a predefined step.
Shift+Arrow Up
Increments the value of the number input by the largeStep amount.
Shift+Arrow Down
Decrements the value of the number input by the largeStep amount.
Alt+Arrow Up
Increments the value of the number input by the smallStep amount.
Alt+Arrow Down
Decrements the value of the number input by the smallStep amount.
Home
Sets the value of the number input to its minimum allowed value.
End
Sets the value of the number input to its maximum allowed value.
Enter
Submits the value entered in the number input.
Demos
Controlled
The number lives in your own state, starting at 1, and the line under the field changes from "Not 3 yet." to "That's 3." once the value is 3. Control it when another part of the screen reads the number, such as a cart total or a price summary. Leave it uncontrolled when only the form needs it.
Disabled
With disabled on NumberInput, the field and both buttons fade and stop responding, and the value is left out when the form submits. Use it for a number this person can't change right now, such as seats fixed by their plan, with a line nearby that says why. When the value must still reach the server, set readOnly instead.
Field only
The group holds only NumberInputInput, starting at 0, with no step buttons. People type the number or step it with the arrow keys. Use it in a table cell or a dense toolbar, where two buttons per field would crowd the row. Letters still can't get in.
Form
A Quantity field from 1 to 10 sits in a form under the name quantity, and Add to cart reads the form data the way a server would and prints what it got, such as quantity=3. The name goes on NumberInput. Use a plain form like this when the number goes out with other fields, such as a cart line.
Formatted
formatOptions set to US dollars shows the starting value, 19, as $19.00, and every step keeps the currency format. Use it for prices and other amounts where the format is part of what people read. When you only want a symbol beside a plain number, the With input group demo puts one there instead.
Invalid
invalid on NumberInput turns the border red around a value of 32 and tells screen readers the input is invalid. It doesn't stop typing or stepping, and the field can't say what is wrong, so pair it with a message such as "Only 20 left in stock". Use it for rules that min and max can't express.
Mouse wheel
The field starts at 10 with allowMouseWheel set, so turning the wheel over it steps the value. That only happens while the input has focus and the pointer is over it, so scrolling the page past the field leaves it alone. Turn it on in an editor panel where the pointer already rests on the field.
Range
min is 0, max is 10 and the field starts at 5. The buttons stop at either end, and a typed number past them is pulled back into range. Set both for a rating, a percentage or a small count with a fixed band, and only min when the one rule is no negatives.
Scrub
The Quantity label above the field is a NumberInputScrubber: press on it and drag sideways, and the value follows, the way design tools let you nudge a size. The buttons and typing still work. Add it where people adjust numbers by eye, such as dimensions in an editor, and leave it off forms people fill in on a phone.
Size lg
size set to lg raises the input and its buttons from 32 to 36 pixels. Use it when the number is the main control on the screen, such as the quantity on a product page, or when it sits in a row of other large inputs and buttons.
Size md
md is the default size, written out here so you can compare it with the other two: the input and its buttons are 32 pixels tall, the height of the default Input. Leave size out in most forms and the field lines up with its neighbors.
Size sm
size set to sm brings the input and its buttons down to 28 pixels, for a table row, a toolbar or a crowded side panel. On a touch screen each button keeps a 44-pixel tap area at every size, so the small one costs no reach. Keep a visible label, since a short box is easy to overlook.
Step
Two fields: one moves by 5 from 0, the other by 0.1 from 0.1. The step sets how far one press of a button moves the value. Pick one people can predict from the label, whole units for stock counts and tenths for a measurement such as a weight in kilograms.
With field
The input sits in a Field under the label Quantity, with the hint "0 - 100 only" below it and min and max set to match. Use a Field when the number needs a visible label, a hint and later an error message. Ark UI ties the label to the input for you.
With input group
The number sits in an Input Group between a euro sign and the letters EUR, with no step buttons. Use it when the unit is decoration around a plain number and a currency format would change how the number reads. The aria-label on NumberInputInput names the input, since the symbols can't.
FAQ
How do I control the Number Input value in Vue?
Bind v-model on NumberInput to a ref, which then holds the text in the field as a string. For the parsed number, listen to @value-change, whose details also carry valueAsNumber, NaN while the field is empty. Save that one, because with formatOptions set the text is formatted, such as $19.00.
The Controlled demo holds the value this way and compares it with 3.
How do I set a minimum, maximum and step on a Number Input?
Set min, max and step on NumberInput. The buttons move by step and stop at either end, as the Range and Step demos show.
A typed number past either end marks the field invalid while it's out of range and is clamped back in when the field loses focus. Set clampValueOnBlur to false to keep it there and let your own validation explain it. Typed numbers aren't rounded to the step.
How do I format a Number Input as currency or a percentage?
Pass formatOptions, which takes the options of Intl.NumberFormat. { style: "currency", currency: "USD" } shows 19 as $19.00, as in the Formatted demo. With { style: "percent" } the value is a fraction, so 0.25 shows as 25%.
With the percent style, Ark UI steps by 0.01, one percent, unless you set step yourself.
With either style, the value Ark UI reports is the text as the field shows it, such as $19.00, so read valueAsNumber when you need the number.
How do I submit a Number Input value with a form?
Give NumberInput a name, and Ark UI puts it on the input itself, so the form receives the text in the field: 12 for a plain number, $12.00 with currency formatting, which the server has to parse. A number typed past max and sent with Enter goes as typed, since Ark UI pulls it back in range only when the field loses focus, so check the range on the server too. Resetting the form puts back the starting value.
The Form demo sends a quantity and shows what the form received.
Can a Number Input change value with the mouse wheel?
Yes, once you set allowMouseWheel on NumberInput: the wheel then steps the value while the input has focus and the pointer is over it, and the page doesn't scroll underneath. It's off by default, so someone scrolling a long form past the field doesn't change a quantity by accident. The Mouse wheel demo has it on.
How do I let people drag to change a Number Input value?
Put a NumberInputScrubber above the group with the label text inside it, as the Scrub demo does with Quantity. It renders the label and makes it a handle: press on it and drag sideways to move the value.
While you drag, Ark UI locks the pointer and draws its own cursor, except in Safari, so the drag can run past the edge of the screen. It starts from a mouse press, so on a phone the buttons remain the way in.
Is the Ark UI Number Input accessible?
Yes, once it has a name: put it in a Field with a FieldLabel, which Ark UI ties to the input, or give NumberInputInput an aria-label. The input has the spinbutton role with its value and limits, the arrow keys step it, Shift and Alt change the size of the step, and Home and End jump to min and max. Those default to the largest safe integers, so set both, or Home turns a quantity into -9007199254740991.
When should I use a Number Input instead of an input with type number?
Use the Number Input when the number needs a currency or percent format, step buttons that look the same in every browser, or a min and max it is pulled back inside. A native number input draws the browser's own spinners, can't format the value, accepts the letter e for exponents, and only reports an out-of-range number through form validation.
For digits that aren't a quantity, such as a postal code or a one-time code, use an Input with inputMode set to numeric, or an Input OTP. Step buttons mean nothing on those.
API Reference
NumberInput
<div>data-slot="number-field"
PropType
value?string
The controlled value of the input. Two-way with v-model.
defaultValue?string
The initial value of the input when rendered.
Use when you don't need to control the value of the input.
allowMouseWheel?boolean
Whether to allow mouse wheel to change the value.
allowOverflow?boolean
Whether to allow the value overflow the min/max range.
Default
true
clampValueOnBlur?boolean
Whether to clamp the value when the input loses focus (blur).
Default
true
dir?"ltr" | "rtl"
The document's text/writing direction.
Type
"ltr" | "rtl"
Default
"ltr"
disabled?boolean
Whether the number input is disabled.
focusInputOnChange?boolean
Whether to focus input when the value changes.
Default
true
form?string
The associate form of the input element.
formatOptions?Intl.NumberFormatOptions
The options to pass to the Intl.NumberFormat constructor.
id?string
The unique identifier of the machine.
ids?object
The ids of the elements in the number input. Useful for composition.