Web Components

webc/aria-idrefs-same-tree

id references (for, aria-labelledby, aria-describedby, aria-controls) point at an element in the same DOM tree, not across a shadow root.

seriousmanualWCAG 1.3.1, 4.1.2 · Afe-web-components

Why

An id is only looked up inside its own tree. <label for="email"> in the page cannot reach <input id="email"> inside a component's shadow root, and aria-describedby="hint" inside the shadow root cannot reach a hint in the page. The relationship looks right in the source and is simply missing for screen readers: the field is announced without a name or a description.

Fix

Keep the label and the control in the same tree: render the label inside the component from an attribute or a slot, or make the host form-associated so an outer <label for="host-id"> labels the host (webc/form-associated). For descriptions, pass the text in and render it next to the inner control. Test with a screen reader or the browser's accessibility tree; automated checkers do not reliably follow references across shadow roots. Cross-root references (referenceTarget) are still being specified; do not rely on them yet.

Examples

<!-- bad: the label cannot see the input inside the shadow root -->
<label for="email">Email</label>
<acme-input id="email"></acme-input>
<!-- good: the component renders its own label -->
<acme-input label="Email" type="email" autocomplete="email"></acme-input>

Sources

Facts

Id
webc/aria-idrefs-same-tree
Severity
serious
Check
manual a person reviews it; the report lists it as a checklist
Applies to
jsx html
WCAG 2.2
1.3.1, 4.1.2, level A
Taught by the skill
fe-web-components Web components and Lit
Since version
0.1.0

Rule file on GitHub

Read it in the terminal

npx github:dawidolko/frontend-skills explain webc/aria-idrefs-same-tree