-
Notifications
You must be signed in to change notification settings - Fork 791
/
is-hidden.js
56 lines (46 loc) · 1.32 KB
/
is-hidden.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 getNodeFromTree from './get-node-from-tree';
/**
* Determine whether an element is visible
* @method isHidden
* @memberof axe.utils
* @param {HTMLElement} el The HTMLElement
* @param {Boolean} recursed
* @return {Boolean} The element's visibilty status
* @deprecated use isVisibleToScreenreader
*/
function isHidden(el, recursed) {
const node = getNodeFromTree(el);
// 9 === Node.DOCUMENT
if (el.nodeType === 9) {
return false;
}
// 11 === Node.DOCUMENT_FRAGMENT_NODE
if (el.nodeType === 11) {
el = el.host; // grab the host Node
}
if (node && node._isHidden !== null) {
return node._isHidden;
}
const style = window.getComputedStyle(el, null);
if (
!style ||
!el.parentNode ||
style.getPropertyValue('display') === 'none' ||
(!recursed &&
// visibility is only accurate on the first element
style.getPropertyValue('visibility') === 'hidden') ||
el.getAttribute('aria-hidden') === 'true'
) {
return true;
}
const parent = el.assignedSlot ? el.assignedSlot : el.parentNode;
const hidden = isHidden(parent, true);
// cache the results of the isHidden check on the parent tree
// so we don't have to look at the parent tree again for all its
// descendants
if (node) {
node._isHidden = hidden;
}
return hidden;
}
export default isHidden;