-
Notifications
You must be signed in to change notification settings - Fork 78
Description
Visible label is part of accessible name compares the visible text content of a widget with its accessible name, it maps to 2.5.3 which compares the "label" with the name, where "label" is used in the generic WCAG sense of the term.
Now, I've seen cases that look like:
<button aria-label="Subscribe to newsletter" aria-describedby="label">
<span>Subscribe to newsletter</span></br>
<span style="font-size: smaller" id="label">We send 1 mail per month.</span>
</button>
This button
fails the rule because the accessible name "Subscribe to newsletter" does not contain the visible text content "Subscribe to newsletter We send 1 mail per month."
I am, however, not convinced that it should fail 2.5.3 🤔
This essentially boils down to define what WCAG calls "label" and what is the "label" in this case.
The Understanding document of 2.5.3 has some discussion (second to last paragraphs of "Intent") about the fact that "label" should be interpreted fairly strictly for this SC, notably:
It is important to bias towards treating only the adjacent text as a label because liberal interpretations of what constitutes a text label can jeopardize the value of this Success Criterion (SC) by lessening predictability.
Similarly, Technique G211, which is sufficient for 2.5.3, has this example of stacked labels (edited with style):
<form>
<label style="font-size: larger; font-weight: bolder" class="label" for="example-2">
Password
</label></br>
<span style="font-size: smaller" id="example-2-hint" class="hint">
Passwords must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.
</span></br>
<input class="input" id="example-2" name="example-2" type="text" aria-describedby="example-2-hint">
</form>
Where the intermediate text is not part of the "label".
It is fairly easy to tweak it and move the description inside the label
element:
<form>
<label class="label" for="example-2">
<span id="label" style="font-size: larger; font-weight: bolder">Password</span></br>
<span style="font-size: smaller" id="example-2-hint" class="hint">
Passwords must be 10 or more characters, and contain at least one capital, numeric and non-alphanumeric.
</span>
</label></br>
<input class="input" id="example-2" name="example-2" type="text" aria-describedby="example-2-hint" aria-labelledby="label">
</form>
While this is arguably worse code, this is essentially the same thing as the example in G211 previously and should therefore satisfy 2.5.3.
Now, this is not Applicable for the rule, but it seems to indicate that WCAG consider "label" to be the "main label", not necessarily the full thing with extra indication, and therefore I think the button
at the start of this issue should satisfy 2.5.3, but fails the rule 💥