Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

data-stepper

Visible − and + buttons for a native number input. Steps exactly like the arrow keys, follows disabled and readonly, and re-syncs after a form reset.

Overview

data-stepper adds decrease and increase buttons around a native <input type="number">. The buttons call the input's own stepDown() and stepUp(), so min, max, step and the step base behave exactly as they do for the arrow keys, and the value the buttons produce is always valid.

The input stays the control: it keeps focus, submits with the form and validates as usual. The buttons are mouse and touch helpers outside the tab order.

Usage

The script wraps the input in a .number-wrapper with a .number-dec button before it and a .number-inc button after it, and hides the browser's spinners. Without JavaScript the input is a normal number field with the browser spinners.

Options

AttributeValuesDefaultEffect
data-stepper boolean — Adds the buttons to input[type="number"].
data-label-decrease string Decrease Accessible name of the − button. Same attribute as on <stepper-wc>.
data-label-increase string Increase Accessible name of the + button.
min, max native none The − button is disabled at min, the + button at max. Without them neither button ever disables.
step native 1 The amount per press, counted from the step base (min, else the initial value). With min="1" step="5", 2 steps up to 6, not 7. With step="any" the buttons move by 1.
disabled, readonly native — Both buttons are disabled and ignore presses, including inside a disabled <fieldset>. Changes after load are picked up.
data-stepper-init boolean — Set by the script. The spinner hiding is keyed on it, so a number field keeps its spinners until the buttons exist.

Events

A button press that changes the value fires input and then change on the input, as a keyboard step would. A press that changes nothing (at a bound) fires nothing. The button states also update on the input's own input and change events and after the form is reset.

Styling

There are no public custom properties. The wrapper uses the same edge as text fields, --input-border (which falls back to --control-border), and the buttons use --color-surface-raised. Style the generated classes for anything else:

  • .number-wrapper — the inline-flex frame; shows a --color-interactive border and halo while the input has focus (an outline in forced-colours mode).
  • .number-dec, .number-inc — the buttons; :disabled buttons are dimmed.

Accessibility

  • The input keeps focus and is announced as a spin button with its value. ↑/↓ step it.
  • The buttons have tabindex="-1", so the field is one tab stop. They are named "Decrease" and "Increase" (override with data-label-* for other languages); their icons are aria-hidden.
  • Disabled buttons use the native disabled attribute, at a bound and whenever the input is disabled or read-only.
  • The field needs a visible <label>.

Examples

Decimal steps

Bounds and step base

The seats field counts in fours from 1 (1, 5, 9…). The offset field has no bounds.

Read-only and disabled

Translated button names

In a form, with reset

Step the adults up, then press Reset: the − button disables again at the restored minimum.

Related

data-stepper or stepper-wc

  • data-stepper — a plain number (quantity, guests, weight). The value is a native number input, so validation, autofill and form submission are the browser's.
  • <stepper-wc> — formatted units or currency, durations, a fixed list of values or tokens, or long-press acceleration.
↑