Loading...

Shadow-Boundary ARIA References

RULES.md

An `id` reference (`aria-labelledby`, `aria-describedby`, `aria-controls`, `aria-owns`, `aria-activedescendant`, `<label for>`) only resolves inside the tree it is written in. One that points from light DOM into a shadow root, or out of a shadow root to light DOM, finds nothing and fails silently: no error, no axe failure in many cases, just a control with no name. Inside an element, keep the labelling control and its label in the same shadow root, or take the label as a property/attribute and render it next to the control. To label a shadow-internal control from slotted or light DOM content, set the reflected element properties (`ariaLabelledByElements`, `ariaDescribedByElements`, `ariaControlsElements`) in `firstUpdated`/`updated`; they resolve outward only (shadow tree to light DOM or ancestor trees), never inward, so a host cannot be labelled by its own shadow content this way. They are Baseline Newly available, so feature-detect (`'ariaLabelledByElements' in Element.prototype`) and keep a working label when they are missing (see the Browser Support Policy rule `4e0800ef-32ff-42dc-83f0-bbb953d97554`). Focus: when the element wraps one internal focusable control that owns the semantics (an input, a button), attach the shadow root with `delegatesFocus: true` (in Lit, `static shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true }`) instead of putting `tabindex` on the host; do not also give the host a role or state, or focus lands on the inner control and the host's state is skipped. When the host itself is the control (a custom toggle with `role` and `aria-pressed` on the host), put `tabindex="0"` on the host and leave `delegatesFocus` off. Never use a positive `tabindex`. Check this when adding or reviewing labels, descriptions or focus handling in an element; `hax-a11y-audit` checks the authored-content side. Source: Modern Web Guidance `accessible-web-components`. Tracking: <https://github.com/haxtheweb/issues/issues/3298>. In PRAW RULES.md (scope: webcomponents). Nothing enforces this yet.

Status: gap

Connects to

Links