Skip to content

Commit 69a9c3b

Browse files
authored
feat(rule): New aria-toggle-field-label rule (#1450)
1 parent 73d5273 commit 69a9c3b

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

doc/rule-descriptions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| aria-required-children | Ensures elements with an ARIA role that require child roles contain them | Critical | cat.aria, wcag2a, wcag131 | true |
1313
| aria-required-parent | Ensures elements with an ARIA role that require parent roles are contained by them | Critical | cat.aria, wcag2a, wcag131 | true |
1414
| aria-roles | Ensures all elements with a role attribute use a valid value | Serious, Critical | cat.aria, wcag2a, wcag412 | true |
15+
| aria-toggle-field-label | Ensures every ARIA toggle field has an accessible name | Moderate, Serious | wcag2a, wcag412 | true |
1516
| aria-valid-attr-value | Ensures all ARIA attributes have valid values | Critical | cat.aria, wcag2a, wcag412 | true |
1617
| aria-valid-attr | Ensures attributes that begin with aria- are valid ARIA attributes | Critical | cat.aria, wcag2a, wcag412 | true |
1718
| audio-caption | Ensures <audio> elements have captions | Critical | cat.time-and-media, wcag2a, wcag121, section508, section508.22.a | false |
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"id": "aria-toggle-field-label",
3+
"selector": "[role=\"checkbox\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"], [role=\"radio\"], [role=\"switch\"]",
4+
"matches": "aria-form-field-label-matches.js",
5+
"tags": ["wcag2a", "wcag412"],
6+
"metadata": {
7+
"description": "Ensures every ARIA toggle field has an accessible name",
8+
"help": "ARIA toggle fields have an accessible name"
9+
},
10+
"all": [],
11+
"any": [
12+
"aria-label",
13+
"aria-labelledby",
14+
"non-empty-title",
15+
"has-visible-text"
16+
],
17+
"none": ["no-implicit-explicit-label"]
18+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<!-- PASS -->
2+
<!-- checkbox -->
3+
<div id="pass1" role="checkbox">Newspaper</div>
4+
<!-- menuitemcheckbox -->
5+
<ul role="menu">
6+
<li
7+
id="pass2"
8+
role="menuitemcheckbox"
9+
aria-label="Word wrap"
10+
aria-checked="true"
11+
></li>
12+
</ul>
13+
<!-- menuitemradio -->
14+
<p id="pass3Label">Sans-serif</p>
15+
<ul role="menu">
16+
<li
17+
id="pass3"
18+
role="menuitemradio"
19+
aria-labelledby="pass3Label"
20+
aria-checked="true"
21+
></li>
22+
</ul>
23+
<!-- radio -->
24+
<div role="radiogroup">
25+
<div
26+
id="pass4"
27+
role="radio"
28+
aria-checked="false"
29+
tabindex="0"
30+
title="Regular Crust"
31+
></div>
32+
</div>
33+
<!-- switch -->
34+
<div
35+
id="pass5"
36+
role="switch"
37+
aria-checked="true"
38+
aria-label="Toggle blue light:"
39+
>
40+
<span>off</span>
41+
<span>on</span>
42+
</div>
43+
44+
<!-- FAIL -->
45+
<!-- checkbox -->
46+
<div id="fail1" role="checkbox" aria-labelledby="does-not-exist"></div>
47+
<!-- menuitemcheckbox -->
48+
<ul role="menu">
49+
<li id="fail2" role="menuitemcheckbox" aria-checked="true"></li>
50+
</ul>
51+
<!-- menuitemradio -->
52+
<ul role="menu">
53+
<li id="fail3" role="menuitemradio" aria-checked="true"></li>
54+
</ul>
55+
<!-- radio -->
56+
<div role="radiogroup">
57+
<div id="fail4" role="radio" aria-checked="false" tabindex="0"></div>
58+
</div>
59+
<!-- switch -->
60+
<div id="fail5" role="switch" aria-checked="true">
61+
<span></span>
62+
<span></span>
63+
</div>
64+
65+
<!-- INAPPLICABLE -->
66+
<input id="inapplicable1" />
67+
<select id="inapplicable2">
68+
<option value="volvo">Volvo</option>
69+
<option value="saab">Saab</option>
70+
<option value="opel">Opel</option>
71+
</select>
72+
<textarea id="inapplicable3" title="Label"></textarea>
73+
74+
<!-- INCOMPLETE -->
75+
<label>
76+
first name
77+
<div id="canttell1" role="checkbox" aria-label="name"></div>
78+
</label>
79+
<label for="canttell2">first name</label>
80+
<div role="checkbox" id="canttell2" aria-label="name"></div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"description": "aria-toggle-field-label test",
3+
"rule": "aria-toggle-field-label",
4+
"passes": [["#pass1"], ["#pass2"], ["#pass3"], ["#pass4"], ["#pass5"]],
5+
"violations": [["#fail1"], ["#fail2"], ["#fail3"], ["#fail4"], ["#fail5"]],
6+
"incomplete": [["#canttell1"], ["#canttell2"]]
7+
}

0 commit comments

Comments
 (0)