-
Notifications
You must be signed in to change notification settings - Fork 794
/
Copy pathpresentational-role-evaluate.js
56 lines (48 loc) · 1.64 KB
/
presentational-role-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
46
47
48
49
50
51
52
53
54
55
56
import { getExplicitRole, getRole } from '../../commons/aria';
import { getGlobalAriaAttrs } from '../../commons/standards';
import { isFocusable } from '../../commons/dom';
export default function presentationalRoleEvaluate(node, options, virtualNode) {
const explicitRole = getExplicitRole(virtualNode);
// in JAWS, an iframe or frame with an accessible name and a presentational role gets announced
// as "group" rather than being ignored. aria-label is handled by role-conflict resolution and
// aria-labelledby only triggers the group role when it's valid (exists and has content)
if (
['presentation', 'none'].includes(explicitRole) &&
['iframe', 'frame'].includes(virtualNode.props.nodeName) &&
virtualNode.hasAttr('title')
) {
this.data({
messageKey: 'iframe',
nodeName: virtualNode.props.nodeName
});
return false;
}
const role = getRole(virtualNode);
if (['presentation', 'none'].includes(role)) {
this.data({ role });
return true;
}
// if the user didn't intended to make this presentational we fail
if (!['presentation', 'none'].includes(explicitRole)) {
return false;
}
// user intended to make this presentational so inform them of
// problems caused by role conflict resolution
const hasGlobalAria = getGlobalAriaAttrs().some(attr =>
virtualNode.hasAttr(attr)
);
const focusable = isFocusable(virtualNode);
let messageKey;
if (hasGlobalAria && !focusable) {
messageKey = 'globalAria';
} else if (!hasGlobalAria && focusable) {
messageKey = 'focusable';
} else {
messageKey = 'both';
}
this.data({
messageKey,
role
});
return false;
}