Number Input
A number field with minus and plus buttons that keeps the value between `min` and `max`.
<arc-number-input>Overview
NumberInput puts decrement and increment buttons on either side of a text field and draws the three as one bordered control. Use it for an exact value like a quantity. For an approximate value or a wide range, use Slider.
Set min and max and the value is clamped to them. The button at a limit disables itself. step sets how far a button click or arrow key moves the value, and Shift+Arrow moves it 10 steps.
A label renders above the control and is tied to the field with a generated id and for. The events mirror the native control: typing fires arc-input on each keystroke, and the value commits with arc-change on blur or Enter. A button click or an arrow key fires both at once. Every event carries the new value in its detail.
Guidelines
Do
- Set `min` and `max` whenever the value has real limits
- Match `step` to your data: 1 for integers, 0.1 for one decimal place
- Give every number input a `label`, so screen readers announce it and stacked inputs can be told apart
Don't
- Don't set `step` to 0. The buttons and arrow keys then can't change the value
- Don't use it for digits that aren't quantities, like phone numbers. Use Input
Features
- `spinbutton` role with `aria-valuenow`, `aria-valuemin` and `aria-valuemax`
- Hides the browser's own spin buttons so the control looks the same on every platform
- Focus colors the whole control's border with `accent-primary` and a focus ring
- Disabled drops to 50% opacity and blocks pointer events
Preview
Usage
This component needs JavaScript. Use the Web Component or a framework wrapper.
<arc-number-input label="Quantity" value="3" min="1" max="99" step="1"></arc-number-input>import { NumberInput } from '@arclux/arc-ui-react';
export default function Example() {
return (
<NumberInput label="Quantity" value={3} min={1} max={99} step={1} />
);
}<script setup>
import { NumberInput } from '@arclux/arc-ui-vue';
</script>
<template>
<NumberInput label="Quantity" :value="3" :min="1" :max="99" :step="1" />
</template><script>
import { NumberInput } from '@arclux/arc-ui-svelte';
</script>
<NumberInput label="Quantity" value={3} min={1} max={99} step={1} />import { Component } from '@angular/core';
import { NumberInput } from '@arclux/arc-ui-angular';
@Component({
imports: [NumberInput],
template: `
<arc-number-input label="Quantity" [value]="3" [min]="1" [max]="99" [step]="1"></arc-number-input>
`,
})
export class MyComponent {}import { NumberInput } from '@arclux/arc-ui-solid';
export default function Example() {
return (
<NumberInput label="Quantity" value={3} min={1} max={99} step={1} />
);
}import { NumberInput } from '@arclux/arc-ui-preact';
export default function Example() {
return (
<NumberInput label="Quantity" value={3} min={1} max={99} step={1} />
);
}API
valuenumber0- Current numeric value. Reflected as an attribute and updated on user interaction.
stepnumber1- Increment and decrement step size. Arrow keys use this value, Shift+Arrow uses 10x this value.
labelstring''- Label text displayed above the control in uppercase accent font.
namestring''disabledbooleanfalse- Disables interaction, reducing opacity to 40% and blocking pointer events.
minnumber0- Minimum allowed value. The decrement button is disabled when the value reaches this limit.
maxnumber0- Maximum allowed value. The increment button is disabled when the value reaches this limit.
readonlybooleanfalse- Prevents value changes from typing, stepper buttons, and arrow keys while keeping the field focusable and its value submitted.
size'sm' | 'md' | 'lg''md'- Control size.
mdis the default;smandlgscale the field padding. formAssociatedbooleantruepropertiesobject{ // flag(), unlike `disabled`. The exclusion in props.js is specifically // about form-associated *platform* semantics: a `disabled` content // attribute that is merely present makes the element actually disabled // per the HTML spec, and formDisabledCallback assigns the property back, // so no converter can win. Neither of these is platform-mapped: // `required` is enforced by _computeValidity() below and `readonly` by // each component's own interaction handlers, so the stock converter buys // nothing here and costs the usual bug: `required="false"` read as true, // blocking submission of a form the author meant to leave optional. // Finding #48's shape, across all 26 form controls at once. required: flag(false), readonly: flag(false), }- Lit merges static properties up the prototype chain, so every consumer
gets these without declaring them.
requiredparticipates in constraint validation below;readonlyreflects for styling and is enforced by each component's interaction handlers (the mixin can't know which gestures mutate state). autoValidatesbooleantrue- Components that run their own constraint-validation logic (pattern checks, range checks) opt out of the automatic required sync by overriding this to false, and own the whole validity flag set instead.
formvalidityvalidationMessagerequiredbooleanfalse
Methods
checkValidity()boolean- Whether the control currently satisfies its constraints, per the native
constraint-validation API. Fires
invalidon the element when it does not, and reports nothing to the user. reportValidity()boolean- As checkValidity(), but also shows the browser's validation message against the control when it fails.
Events
arc-inputdetail:{ value: number }- Fired on every edit, including each keystroke while typing. Use for live previews.
arc-changedetail:{ value: number }- Fired when the value is committed: blur or Enter after typing, or immediately on a stepper click or arrow key, which are edit and commit in one gesture.