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

disabled

Turns a form control off: it can't be focused, edited or activated, it is skipped by validation, and its value is not submitted. On a fieldset it disables every control inside.

Overview

disabled is a boolean attribute that switches a form control off. A disabled control can't be focused or activated, leaves the tab order, is barred from constraint validation and is left out of the submitted form data. On a <fieldset> it disables every control inside, except those in the fieldset's first <legend>.

Applies to: <button>, <input>, <select>, <textarea>, <fieldset>, <option>, <optgroup>, and form-associated custom elements (VB's <combo-box>, <date-picker>, <star-rating> and others).

Values

Boolean: present means disabled. disabled="false" still disables; remove the attribute (or set el.disabled = false) to enable. A control is also disabled when it sits inside a disabled fieldset (outside its first legend), which :disabled reflects but the control's own disabled property does not.

StateFocusableEditableSubmittedValidatedAnnounced
disabledNoNoNoNo"dimmed" / "unavailable", if reached
aria-disabled="true"YesYes, unless you block itYesYes"dimmed" / "unavailable"
readonlyYesNoYesNo"read only"
inert (on an ancestor)NoNoYesYesNot at all: hidden from assistive technology

Examples

Busy submit button: data-loading, not disabled

Disabling the submit button inside the submit event drops its name/value from the form data and throws focus to <body>. Use data-loading: the button gets aria-disabled="true" and aria-busy="true", keeps focus, shows a spinner, and further clicks are ignored until the submission finishes.

Explain a disabled action

A disabled button can't be focused, so a tooltip or title on it is never reached by keyboard. Put the reason in visible text instead, or keep the control focusable with aria-disabled and handle the click.

Keeping a value but not the editing

Disabled values are not sent. If the server needs the value, use readonly on text fields, or pair a disabled <select> with a hidden input.

In Vanilla Breeze

  • Buttons. :disabled and [aria-disabled="true"] both get opacity: 0.5 and a not-allowed cursor (src/native-elements/button/styles.css).
  • Text fields, selects, textareas. :disabled gets the raised surface (--color-surface-raised) and a not-allowed cursor, with no opacity (src/native-elements/input/styles.css).
  • Fieldsets. fieldset:disabled gets muted text and a dashed border, with no opacity of its own so the dimming doesn't compound with the controls' (src/native-elements/form/styles.css). In forced colours the text and border use GrayText.
  • Conditional sections. data-show-when, data-hide-when and data-wizard-if set disabled on every control in a section they hide, marked data-conditional-disabled, so hidden fields are neither validated nor submitted. Only marked controls are re-enabled; anything you disabled yourself stays disabled (src/lib/form-conditions.js).
  • Enhanced controls follow the state. data-stepper buttons lock when their input is disabled (or inside a disabled fieldset); data-upload ignores drops on a disabled input; data-select-all skips disabled checkboxes; data-autosave never restores into a disabled control.

Accessibility

  • Disabled controls leave the tab order, so keyboard and screen-reader users can miss them entirely. If users need to discover the control and learn why it is unavailable, use aria-disabled="true" and block the action in script; VB styles it the same as disabled for buttons.
  • Disabled controls are exempt from WCAG contrast minimums, but that doesn't make faint text readable. Say why the control is off in nearby text.
  • Don't use inert to make content "read-only". It removes the content from the accessibility tree as well as from interaction; use readonly or aria-disabled.
  • Don't disable the submit button until the form is valid. Users get no explanation; let them submit and show the errors.

Gotchas

  • disabled means nothing on <a>. A link has no disabled state: remove the href (it becomes a placeholder link) or render text instead.
  • Controls in a disabled fieldset report el.disabled === false. Test with el.matches(':disabled').
  • Firefox keeps a <button>'s script-set disabled state across a page reload. Add autocomplete="off" to the button if it should always start from the markup.
  • Disabling a focused control moves focus to <body>. Move focus somewhere useful first.

Related

Which to choose

  • disabled — the control does not apply right now and its value must not be sent.
  • aria-disabled="true" — users should still find the control and hear why it is unavailable.
  • readonly — the value is fixed but must be submitted and readable.
  • data-loading — a button is busy for a moment.
  • data-show-when — a whole section applies only for some answers.
↑