-
Notifications
You must be signed in to change notification settings - Fork 126
/
aria-unsupported-elements.js
41 lines (35 loc) · 1.29 KB
/
aria-unsupported-elements.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
import {
DOM,
aria,
hasProp
} from '../util';
export default [{
msg: 'This element does not support ARIA roles, states and properties.',
AX: 'AX_ARIA_12',
test(tagName, props) {
const reserved = (Object.prototype.hasOwnProperty.call(DOM, tagName) && DOM[tagName].reserved) || false;
const prop = hasProp(props, Object.keys(aria).concat('role'));
return !reserved || !prop;
}
}];
export const description = `
Certain reserved DOM elements do not support ARIA roles, states and properties.
This is often because they are not visible, for example \`meta\`, \`html\`, \`script\`,
\`style\`. This rule enforces that these DOM elements do not contain the \`role\` and/or
\`aria-*\` props.
`;
export const fail = [{
when: 'the element should not be given any ARIA attributes',
// eslint-disable-next-line jsx-a11y/aria-unsupported-elements
render: React => <meta charSet="UTF-8" aria-hidden="false" />
}];
export const pass = [{
when: 'the reserved element is not given an illegal prop',
render: React => <meta charSet="UTF-8" />
}, {
when: 'an illegal prop is given to a non-reserved element',
render: React => <div aria-hidden />
}, {
when: 'an illegal prop is given to an unknown element',
render: React => <g aria-hidden />
}];