SpinButton
A numeric input with decrement/increment buttons (APG spinbutton pattern).
- **Keyboard** on the input: ArrowUp/ArrowDown step by step, PageUp/PageDown by largeStep (default ten steps), Home/End jump to min/max when they are finite (Shift+Home and Shift+End keep their native text-selection instead). The −/+ buttons are not tab stops and never take focus, so focus stays on the spinbutton and screen readers announce the new value.
- **Pointer** on the −/+ buttons (mouse, touch or pen): a short press steps once, on release (its click), never on the press alone, so a finger that starts a scroll on a button changes nothing. Holding a button repeats the step: the first after 300ms, then faster, every 80ms after about a second (Fluent's timing). A hold stops when the button is released, the pointer leaves it or the press turns into a scroll, at the bound, when the window loses focus, and when the spin button becomes disabled or read-only. Only the primary button of a primary pointer holds: a second finger, a secondary button or a Ctrl+press with a mouse (the secondary click on macOS) neither starts a hold nor ends one. A click without a press (a screen reader, element.click()) steps once. The buttons open no context menu (a long press on touch would), show no iOS callout, and allow no text selection or double-tap zoom.
- **Typing** edits a draft: the value is parsed, clamped and committed on blur or Enter (Escape reverts). Text that is not a number is flagged with aria-invalid and reverted on blur. Steps (keys and buttons) start from the typed number, and the −/+ buttons are disabled when that number is at min/max. Steps are rounded to the precision of step and of the value, so 0.1 + 0.2 is 0.3; precision rounds every committed value, typed or stepped, to a fixed number of decimals instead, without padding it (pad with displayValue).
- **Routing**: ref, id, ARIA, native input attributes and focus/keyboard handlers go to the <input role="spinbutton">; className, style, data-* and other handlers stay on the root (slotProps.root.ref reaches it). Inside a Field it picks up the label, hint, error and required state automatically. It has no built-in name: pass aria-label/aria-labelledby or use a label (development warning otherwise).
- **Forms**: with name the committed value is submitted; required makes the input natively required; a form reset restores defaultValue.
- **Empty values**: allowEmpty lets the value become null (an empty field). Clearing the text and committing it (blur or Enter) sets the value to null, uncontrolled too; stepping up or down from an empty value starts at 0 and clamps to the nearest bound. required (its own, or a required Field's) still blocks submitting an empty value: the check runs on the HiddenInput that carries the committed value, not on the shown text, so it keeps working even when the shown text is not empty.
- **Display text**: displayValue shows formatted text ($1.00) for the value while the field is not being edited, and as its aria-valuetext; while the field has focus and can be edited it shows the plain number instead, so typing still edits the number (a consumer aria-valuetext always wins). It applies only while value is controlled: an uncontrolled spin button ignores it and warns once in development.
- **Size and appearance**: size resolves from its own prop, then the surrounding Field's size, then WaveProvider inputDefaults.size, else 'medium'; appearance from its own prop, then WaveProvider inputDefaults.appearance, else 'outline'; both render as data-size and data-appearance on the root. SpinButton takes every size the other fields do, and unlike 0.7 its root is now exactly as tall as theirs, with its step buttons and input taking up that height; sizing the root wider widens the input instead of leaving empty space inside it. The step buttons keep a 1px separator from the input only in outline; the other appearances have none.
- The −/+ buttons are named "Decrement"/"Increment"; labels localizes the names.
Examples
Default
export const Default: Story = {};Min Max
export const MinMax: Story = {
args: {
'aria-label': 'Guests',
defaultValue: 5,
min: 0,
max: 10,
},
};Decimal Step
export const DecimalStep: Story = {
args: {
'aria-label': 'Weight in kilograms',
defaultValue: 1.5,
min: 0,
step: 0.1,
},
};Disabled
export const Disabled: Story = {
args: {
'aria-label': 'Seats',
defaultValue: 3,
disabled: true,
},
};Invalid
export const Invalid: Story = {
args: {
'aria-label': 'Tickets',
defaultValue: 12,
'aria-invalid': true,
'aria-describedby': 'spin-button-invalid-error',
},
render: (args) => (
<div className="flex flex-col gap-1">
<SpinButton {...args} />
<span id="spin-button-invalid-error" className="text-wave-caption-1 text-wave-error">
You can book at most 10 tickets.
</span>
</div>
),
};Controlled
Value: 40
export const Controlled: Story = {
args: {
'aria-label': 'Volume',
min: 0,
max: 100,
step: 5,
},
render: function ControlledStory(args) {
const [value, setValue] = useState(40);
return (
<div className="flex flex-col gap-2">
<SpinButton
{...args}
value={value}
onValueChange={(next: number | null) => {
if (next === null) return;
setValue(next);
args.onValueChange?.(next);
}}
/>
<p className="text-wave-body-1 text-wave-foreground">Value: {value}</p>
</div>
);
},
};Display Value
export const DisplayValue: Story = {
args: { 'aria-label': 'Price' },
render: (args) => <CurrencySpinButton {...args} />,
};Allow Empty
export const AllowEmpty: Story = {
render: () => <SpinButton aria-label="Guests (optional)" allowEmpty min={1} max={12} />,
};Precision
export const Precision: Story = {
args: { 'aria-label': 'Weight in kg', precision: 2, step: 0.25, defaultValue: 1.5 },
};Full Width
export const FullWidth: Story = {
args: { 'aria-label': 'Quantity', className: 'w-full' },
};Sizes And Appearances
export const SizesAndAppearances: Story = {
render: (args) => (
<SizeAppearanceGrid
render={(size, appearance) => (
<SpinButton
{...args}
size={size}
appearance={appearance}
aria-label={`${size} ${appearance}`}
/>
)}
/>
),
};Props
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
allowEmpty | boolean | No | false | Allows an empty value ( |
value | number | null | No | Controlled numeric value. | |
defaultValue | number | null | No | 0 | Initial value for uncontrolled usage (also what a form reset restores). |
onValueChange | ((value: number) => void) | ((value: number | null) => void) | No | Called with the new value when it changes: a step (buttons, arrow keys, PageUp/PageDown, Home/End) or a typed value committed on blur or Enter. Not called while the user is typing, nor when the value stays the same. | |
min | number | No | -Infinity | Minimum allowed value. |
max | number | No | Infinity | Maximum allowed value. |
step | number | No | 1 | Step of the increment/decrement buttons and of ArrowUp/ArrowDown. |
largeStep | number | No | step * 10 | Step of PageUp/PageDown. |
precision | number | No | Decimals every committed value is rounded to, typed or stepped (0–20); the number is not padded (use | |
disabled | boolean | No | Whether the spin button is disabled and non-interactive. | |
name | string | No | Form field name. With a name, the committed value is submitted with the form. | |
form | string | No | Id of the form the spin button belongs to, when it is rendered outside that form. | |
labels | SpinButtonLabels | No | Names of the −/+ step buttons (not tab stops, but in the accessibility tree), for localization. Unset members keep their English defaults. | |
displayValue | string | No | Text shown for the value while the field is not being edited, and its | |
size | 'small' | 'medium' | 'large' | No | Size of the field: SpinButton is 24, 32 or 40px tall like every field; its buttons are square-ish, 24, 32 or 40px wide. | |
appearance | 'outline' | 'underline' | 'filled-darker' | 'filled-lighter' | No | Look of the field: The step buttons keep a 1px separator from the input only in | |
ref | React.Ref<HTMLInputElement> | No | Ref to the | |
slotProps | { root?: SlotPart<'div'>; decrementButton?: SlotPart<'button'>; input?: SlotPart<'input'>; incrementButton?: SlotPart<'button'> } | No | Props for the elements the SpinButton draws, by part, merged into each part's own (Fluent UI's |
Any other prop is passed to the element it renders (HTMLDivElement).
Parts
rootdecrementButtoninputincrementButton
Stable class names
| Part | Class |
|---|---|
root | wave-spin-button |
decrementButton | wave-spin-button__decrement-button |
input | wave-spin-button__input |
incrementButton | wave-spin-button__increment-button |