forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlandmark-unique-matches.js
50 lines (43 loc) · 1.5 KB
/
landmark-unique-matches.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
import { findUpVirtual, isVisible } from '../commons/dom';
import { getRole } from '../commons/aria';
import { getAriaRolesByType } from '../commons/standards';
import { accessibleTextVirtual } from '../commons/text';
function landmarkUniqueMatches(node, virtualNode) {
/*
* Since this is a best-practice rule, we are filtering elements as dictated by ARIA 1.1 Practices regardless of treatment by browser/AT combinations.
*
* Info: https://www.w3.org/TR/wai-aria-practices-1.1/#aria_landmark
*/
var excludedParentsForHeaderFooterLandmarks = [
'article',
'aside',
'main',
'nav',
'section'
].join(',');
function isHeaderFooterLandmark(headerFooterElement) {
return !findUpVirtual(
headerFooterElement,
excludedParentsForHeaderFooterLandmarks
);
}
function isLandmarkVirtual(virtualNode) {
var { actualNode } = virtualNode;
var landmarkRoles = getAriaRolesByType('landmark');
var role = getRole(actualNode);
if (!role) {
return false;
}
var nodeName = actualNode.nodeName.toUpperCase();
if (nodeName === 'HEADER' || nodeName === 'FOOTER') {
return isHeaderFooterLandmark(virtualNode);
}
if (nodeName === 'SECTION' || nodeName === 'FORM') {
var accessibleText = accessibleTextVirtual(virtualNode);
return !!accessibleText;
}
return landmarkRoles.indexOf(role) >= 0 || role === 'region';
}
return isLandmarkVirtual(virtualNode) && isVisible(node, true);
}
export default landmarkUniqueMatches;