1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | import {getOwnerWindow} from '@react-aria/utils';
|
14 |
|
15 | function isStyleVisible(element: Element) {
|
16 | const windowObject = getOwnerWindow(element);
|
17 | if (!(element instanceof windowObject.HTMLElement) && !(element instanceof windowObject.SVGElement)) {
|
18 | return false;
|
19 | }
|
20 |
|
21 | let {display, visibility} = element.style;
|
22 |
|
23 | let isVisible = (
|
24 | display !== 'none' &&
|
25 | visibility !== 'hidden' &&
|
26 | visibility !== 'collapse'
|
27 | );
|
28 |
|
29 | if (isVisible) {
|
30 | const {getComputedStyle} = element.ownerDocument.defaultView as unknown as Window;
|
31 | let {display: computedDisplay, visibility: computedVisibility} = getComputedStyle(element);
|
32 |
|
33 | isVisible = (
|
34 | computedDisplay !== 'none' &&
|
35 | computedVisibility !== 'hidden' &&
|
36 | computedVisibility !== 'collapse'
|
37 | );
|
38 | }
|
39 |
|
40 | return isVisible;
|
41 | }
|
42 |
|
43 | function isAttributeVisible(element: Element, childElement?: Element) {
|
44 | return (
|
45 | !element.hasAttribute('hidden') &&
|
46 |
|
47 | !element.hasAttribute('data-react-aria-prevent-focus') &&
|
48 | (element.nodeName === 'DETAILS' &&
|
49 | childElement &&
|
50 | childElement.nodeName !== 'SUMMARY'
|
51 | ? element.hasAttribute('open')
|
52 | : true)
|
53 | );
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | export function isElementVisible(element: Element, childElement?: Element) {
|
63 | return (
|
64 | element.nodeName !== '#comment' &&
|
65 | isStyleVisible(element) &&
|
66 | isAttributeVisible(element, childElement) &&
|
67 | (!element.parentElement || isElementVisible(element.parentElement, element))
|
68 | );
|
69 | }
|