-
Notifications
You must be signed in to change notification settings - Fork 781
/
invalidrole-evaluate.js
45 lines (41 loc) · 1.02 KB
/
invalidrole-evaluate.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
import { isValidRole } from '../../commons/aria';
import { tokenList } from '../../core/utils';
/**
* Check that each role on an element is a valid ARIA role.
*
* Valid ARIA roles are listed in the `ariaRoles` standards object.
*
* ##### Data:
* <table class="props">
* <thead>
* <tr>
* <th>Type</th>
* <th>Description</th>
* </tr>
* </thead>
* <tbody>
* <tr>
* <td><code>String[]</code></td>
* <td>List of all invalid roles</td>
* </tr>
* </tbody>
* </table>
*
* @memberof checks
* @return {Boolean} True if the element uses an invalid role. False otherwise.
*/
function invalidroleEvaluate(node, options, virtualNode) {
const allRoles = tokenList(virtualNode.attr('role'));
const allInvalid = allRoles.every(
role => !isValidRole(role.toLowerCase(), { allowAbstract: true })
);
/**
* Only fail when all the roles are invalid
*/
if (allInvalid) {
this.data(allRoles);
return true;
}
return false;
}
export default invalidroleEvaluate;