This repository has been archived by the owner on Jan 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcustom_a11y_rules.js
242 lines (238 loc) · 8.82 KB
/
custom_a11y_rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
var customRules = {
'rules': [
{
'id': 'description',
'enabled': false,
'tags': [ 'edx-custom' ]
},
{
'id': 'caption',
'enabled': false,
'tags': [ 'edx-custom' ]
},
{
'id': 'nav-aria-label',
'selector': 'nav',
'enabled': true,
'tags': [ 'edx-custom' ],
'all': [
'nav-aria-label-present',
'nav-aria-label-value'
],
'any': [],
'none': [],
'metadata': {
'description': 'Ensures <nav> elements have valid aria-label attribute.',
'help': '<nav> elements MUST have an aria-label, and the aria-label MUST NOT have ' +
'\'navigation\' or \'nav\' as part of the value.',
'helpUrl': 'https://openedx.atlassian.net/wiki/display/A11Y/edX+Specific+Accessibility+Tests'
}
},
{
'id': 'link-href',
'selector': 'a',
'enabled': true,
'tags': [ 'edx-custom' ],
'all': [
'link-href',
'link-href-internal'
],
'any': [],
'none': [],
'metadata': {
'description': 'Ensures <a> elements have acceptable href values',
'help': 'all links must have an href whose value MUST NOT be empty or "#"',
'helpUrl': 'https://openedx.atlassian.net/wiki/display/A11Y/edX+Specific+Accessibility+Tests'
}
},
{
'id': 'skip-link',
'selector': 'a[href]',
'pageLevel': true,
'enabled': true,
'tags': ['edx-custom'],
'all': [],
'any': ['skip-link'],
'none': [],
'metadata': {
'description': 'Ensures that all skip links have a valid target',
'help': 'All skip links should have a valid target, allowing users to skip the navigation',
'helpUrl': 'https://dequeuniversity.com/rules/axe/3.2/skip-link'
}
},
{
'id': 'icon-aria-hidden',
'selector': 'span.icon, span.fa, i.icon, i.fa',
'enabled': true,
'excludeHidden': false,
'tags': ['edx-custom'],
'all': ['icon-aria-hidden'],
'any': [],
'none': [],
'metadata': {
'description': 'Ensures all icon-font elements are aria-hidden',
'help': 'All icon-fonts should have aria-hidden="true"',
'helpUrl': 'https://openedx.atlassian.net/wiki/display/A11Y/edX+Specific+Accessibility+Tests'
}
},
{
'id': 'section',
'selector': 'section',
'enabled': true,
'excludeHidden': false,
'tags': ['edx-custom'],
'all': ['section-heading-first-child'],
'any': [],
'none': [],
'metadata': {
'description': 'Ensures all sections have a heading as the first child',
'help': 'All <section> elements should have a heading as its first child',
'helpUrl': 'https://openedx.atlassian.net/wiki/display/A11Y/edX+Specific+Accessibility+Tests'
}
},
{
'id': 'icon-element',
'selector': 'span.icon, span.fa, i.icon, i.fa',
'enabled': true,
'excludeHidden': false,
'tags': ['edx-custom'],
'all': ['icon-correct-element'],
'any': [],
'none': [],
'metadata': {
'description': 'Ensures all icon-font use span instead of i',
'help': 'All icon-fonts should use a span element, not an i',
'helpUrl': 'https://openedx.atlassian.net/wiki/display/A11Y/edX+Specific+Accessibility+Tests'
}
}
],
'checks': [
{
'id': 'nav-aria-label-present',
'metadata': {
'impact': 'critical',
'messages': {
'pass': 'all <nav> elements MUST have an aria-label or aria-labelledby attribute',
'fail': 'all <nav> elements MUST have aria-label or aria-labelledby attribute'
}
},
evaluate: function(node, options) {
axe._tree = axe.utils.getFlattenedTree(node);
return axe.commons.aria.label(node) !== null;
}
},
{
'id': 'nav-aria-label-value',
'metadata': {
'impact': 'critical',
'messages': {
'pass': 'aria-label values on <nav> elements MUST NOT have' +
' "navigation" or "nav" as part of their value',
'fail': 'aria-label values on <nav> elements MUST NOT have' +
' "navigation" or "nav" as part of their value'
}
},
evaluate: function(node, options) {
axe._tree = axe.utils.getFlattenedTree(node);
var label = axe.commons.aria.label(node) || '',
words = label.toLowerCase().split(' ');
return words.indexOf('nav') < 0 && words.indexOf('navigation') < 0;
}
},
{
'id': 'link-href',
'metadata': {
'impact': 'critical',
'messages': {
'pass': 'href value MUST NOT be empty or "#"',
'fail': 'href value MUST NOT be empty or "#"'
}
},
evaluate: function(node, options) {
var href = node.getAttribute('href');
if (href === null || href === '' || href === '#') {
return false;
} else {
return true;
}
}
},
{
'id': 'link-href-internal',
'metadata': {
'impact': 'critical',
'messages': {
'pass': 'internal link must have focusable target',
'fail': 'internal link must have focusable target'
}
},
evaluate: function(node, options) {
var href = node.getAttribute('href') || '',
linkTarget,
rel = node.getAttribute('rel') || '';
if (href.startsWith('#') && href.length > 1 && rel !== 'leanModal') {
linkTarget = document.querySelector(href);
if (!linkTarget) {
return false;
}
return axe.commons.dom.isFocusable(linkTarget);
} else {
return true;
}
}
},
{
'id': 'icon-aria-hidden',
'metadata': {
'impact': 'critical',
'messages': {
'pass': 'icon elements should be aria-hidden',
'fail': 'icon elements should be aria-hidden'
}
},
evaluate: function(node, options) {
return axe.utils.isHidden(node);
}
},
{
'id': 'section-heading-first-child',
'metadata': {
'impact': 'minor',
'messages': {
'pass': '<section> elements should have a heading as its first child',
'fail': '<section> elements should have a heading as its first child'
}
},
evaluate: function(node, options) {
if (node.children.length === 0) {
return false;
}
var childNode = node.children[0].nodeName,
validHeadings = ['H1', 'H2', 'H3', 'H4', 'H5', 'H6'];
if (childNode === 'HEADER' && node.children[0].children.length > 0) {
childNode = node.children[0].children[0].nodeName;
}
return validHeadings.indexOf(childNode) > -1;
}
},
{
'id': 'icon-correct-element',
'metadata': {
'impact': 'minor',
'messages': {
'pass': 'icon-fonts should use the span element, not i',
'fail': 'icon-fonts should use the span element, not i'
},
},
evaluate: function(node, options) {
var elem = node.nodeName,
validElems = ['SPAN'];
if (validElems.indexOf(elem) > -1) {
return true;
} else {
return false;
}
}
}
]
};