control-has-associated-label
Configuration
Rule Details
Enforce that a control (an interactive element) has a text label.
There are several ways to supply a control with a text label:
- Provide text content inside the element.
- Set
aria-labelon the element. - Set
aria-labelledbyand point it at an element with an accessible label. - For an
imginside the control, set itsaltattribute.
The rule is permissive about runtime-resolvable labels: when the label
comes from an expression ({maybeLabel}) the rule assumes it will
provide a label.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Rule Options
This rule takes one optional object argument:
labelAttributes— extra attribute names to treat as labels in addition toalt,aria-label, andaria-labelledby. Useful when a custom component renders a label from a specific prop (e.g.label).controlComponents— custom React component names to treat as interactive controls. The top-level trigger uses exact matching; the recursive children-walk's React-component fallback uses minimatch glob patterns (mirrors upstream).ignoreElements— elements that should not be considered interactive controls (e.g.input,textarea, where labels are commonly supplied by a wrapping<label>).ignoreRoles— ARIA roles that should not be considered interactive controls.depth(default2, max25) — how deep within the JSX subtree the rule should look for an accessible label.
The link tag is always ignored — the upstream rule hard-codes this
exemption and it cannot be disabled.
Examples of incorrect code for this rule with
{ "controlComponents": ["CustomControl"] }:
Examples of correct code for this rule with
{ "depth": 3, "controlComponents": ["CustomControl"] }:
Examples of correct code for this rule with
{ "labelAttributes": ["label"] }:
Accessibility guidelines
- WCAG 1.3.1 — Info and Relationships
- WCAG 3.3.2 — Labels or Instructions
- WCAG 4.1.2 — Name, Role, Value