Stepper for values that <input type='number'> + data-stepper cannot reach: formatted units, currency, time, token-snap scales, discrete enums.
Overview
<stepper-wc> is a stepper for values that the native number input
cannot represent: formatted units (e.g. $5.00, 12px,
50%), durations (15:00), byte sizes, token-snap design-system
scales, and discrete enums. Plus optional long-press acceleration for large ranges.
It participates in form submission via ElementInternals. The inner
display element carries role="spinbutton" with the appropriate
aria-valuenow / aria-valuemin / aria-valuemax /
aria-valuetext for assistive tech.
Modes
The mode is auto-detected from attributes, first match wins:
| Trigger attribute | Mode | What it does |
data-options | enum | Step through a labeled list of options. |
data-values | token | Step through a fixed scale (e.g. spacing tokens). |
data-format or data-suffix | formatted | Numeric value with formatting (currency, percent, duration, bytes, suffix). |
| none | numeric | Plain numeric stepping. Logs a console hint pointing at data-stepper. |
Formatted units
Numeric value with locale-aware formatting via Intl.NumberFormat for
number, currency, and percent; custom formatters
for duration (seconds → M:SS / H:MM:SS) and
bytes (decimal SI: KB, MB, GB…).
1
<stepper-wc data-min="0" data-max="64" data-suffix="px" value="12"></stepper-wc>
1
<stepper-wc data-format="currency" data-currency="USD" data-min="0" data-step="0.5" value="5"></stepper-wc>
1
<stepper-wc data-format="duration" data-min="0" data-max="3600" data-step="300" value="900"></stepper-wc>
The percent formatter treats the stored value as a 0–100 percentage
(the displayed string divides by 100 internally for Intl.NumberFormat's
style: 'percent'). So value="50" renders as
50%, not 5000%.
Token-snap
Step through a curated list of values. Useful for design-system scales where you
want quantization rather than arbitrary numbers.
1
<stepper-wc data-values="0,4,8,12,16,24,32,48,64" data-suffix="px" value="16"></stepper-wc>
1
<stepper-wc data-values="--size-xs,--size-s,--size-m,--size-l,--size-xl" data-show-label value="--size-m"></stepper-wc>
If the current value is off-scale, the first step snaps to the nearest entry
by numeric distance (numeric values) or to index 0 (non-numeric).
data-show-label strips a leading -- from custom-property tokens
for nicer display.
Discrete enum
Step through labeled options. data-options accepts JSON
[{value, label}] or a comma-separated shorthand where value equals label.
1
<stepper-wc data-options="low,medium,high,critical" value="medium"></stepper-wc>
1
<stepper-wc value="m" data-options='[{"value":"s","label":"Small"},{"value":"m","label":"Medium"},{"value":"l","label":"Large"},{"value":"xl","label":"X-Large"}]'></stepper-wc>
Long-press acceleration
Opt in with data-accelerate. Hold a button for 500ms to start auto-stepping
at 1× step every 100ms; another 1000ms in, the rate switches to 5× step every 50ms.
Intended for large ranges where multiple taps would be tedious.
1
<stepper-wc data-min="0" data-max="1000" data-step="1" data-accelerate value="0"></stepper-wc>
Form participation
Form-associated via ElementInternals. Set name, drop it inside a
<form>, and the value submits like any input. Resetting the form restores
the authored value (captured once, so moving the element does not change
the reset target), and a disabled <fieldset> disables the stepper.
123456
<form> <form-field> <label for="qty">Quantity</label> <stepper-wc id="qty" name="qty" data-min="0" data-max="99" value="1"></stepper-wc> </form-field></form>
Attributes
| Attribute | Type | Default | Description |
value | string | — | Current value. Reflected. |
name | string | — | Form field name. |
data-min | number | — | Numeric lower bound (numeric/formatted modes). |
data-max | number | — | Numeric upper bound (numeric/formatted modes). |
data-step | number | 1 | Step increment. |
data-values | csv | — | Token-snap scale (comma-separated). |
data-options | JSON or csv | — | Enum options ([{value,label}] or csv shorthand). |
data-format | string | — | number | currency | percent | duration | bytes |
data-currency | string | USD | ISO 4217 code (when data-format="currency"). |
data-suffix | string | — | Static suffix appended to display. |
data-show-label | boolean | false | Token mode: show token name (strips leading --). |
data-accelerate | boolean | false | Enable long-press acceleration. |
data-label-decrease | string | Decrease | Accessible name of the − button (translate it). |
data-label-increase | string | Increase | Accessible name of the + button (translate it). |
aria-label / aria-labelledby | string | — | Forwarded to the inner spinbutton when there is no visible <label>. |
disabled | boolean | false | Disables the stepper and removes it from the tab order. A disabled <fieldset> does the same. |
readonly | boolean | false | Locks the value: still focusable, aria-readonly="true", +/- buttons disabled. |
Events
| Event | Bubbles | When |
input | yes | Every value change (button or programmatic). |
change | yes | Every committed value change. (For now, fires alongside input.) |
Keyboard
| Key | Action |
| ↑ / → | Step up (1×). In right-to-left pages ← steps up, matching the button order. |
| ↓ / ← | Step down (1×). In right-to-left pages → steps down. |
| Page Up | Step up (10×). |
| Page Down | Step down (10×). |
| Home | Jump to min (or first option). |
| End | Jump to max (or last option). |
The +/- buttons take tabindex="-1" by design — tab focus lands on
the spinbutton itself, matching the data-stepper convention.
JavaScript API
| Member | Type | Description |
.value | string | Canonical value (number as a string, token, or enum value). Setting it fires input and change. |
.displayText | string (read-only) | The formatted text the user sees, e.g. $5.00, 2.05 KB, Medium. |
.recomputeWidth() | method | Rebuild the width reserve after changing data-min, data-max, data-values, data-options or data-format after upgrade. |
Accessibility
Labelling
The focusable role="spinbutton" is an inner element, so the stepper forwards
its name to it: a <label for> or wrapping <label>
(referenced through aria-labelledby), the host’s
aria-labelledby, or the host’s aria-label. Prefer a visible
<label>; clicking it focuses the spinbutton. Without any of these the
spinbutton has no name.
1234567
<label for="qty">Quantity</label><stepper-wc id="qty" name="qty" data-min="0" data-max="99" data-suffix=" pcs" value="1"></stepper-wc> <span id="sev-label">Severity</span><stepper-wc aria-labelledby="sev-label" data-options="low,medium,high"></stepper-wc> <stepper-wc aria-label="Font size" data-values="12,14,16,20" data-suffix="px"></stepper-wc>
Value
The spinbutton exposes aria-valuenow, aria-valuemin,
aria-valuemax and an aria-valuetext of the formatted display
(“$5.00”, “Medium”). Enum and token modes report the position
(1…n) as the value and the label as the text.
Buttons, readonly and disabled
The −/+ buttons are pointer conveniences with tabindex="-1"; name them in
your language with data-label-decrease / data-label-increase.
readonly keeps the spinbutton focusable with aria-readonly="true"
and disables the buttons; disabled (or a disabled fieldset) takes it out of the
tab order with aria-disabled="true".
Forced colors
In Windows High Contrast the focus ring becomes a Highlight outline on the
spinbutton, since the normal border-and-shadow ring is flattened.
States
Component-computed flags exposed via CustomStateSet:
12
stepper-wc:state(at-min) .stepper-dec { }stepper-wc:state(at-max) .stepper-inc { }