Skip to content

Commit 7e732d7

Browse files
brendankeogh-sfdiasbruno
authored andcommitted
Wrapping getComputedStyle in try catch per PR review
1 parent 31d59b2 commit 7e732d7

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

Diff for: src/helpers/tabbable.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@ function hidesContents(element) {
1818
// If the node is empty, this is good enough
1919
if (zeroSize && !element.innerHTML) return true;
2020

21-
// if the element is not of type Element e.g. shadowRoot
22-
// we cannot go any further
23-
if (!element.isPrototypeOf(Element)) {
21+
try {
22+
// Otherwise we need to check some styles
23+
const style = window.getComputedStyle(element);
24+
return zeroSize
25+
? style.getPropertyValue("overflow") !== "visible" ||
26+
// if 'overflow: visible' set, check if there is actually any overflow
27+
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
28+
: style.getPropertyValue("display") == "none";
29+
} catch(exception) {
2430
return false;
2531
}
26-
27-
// Otherwise we need to check some styles
28-
const style = window.getComputedStyle(element);
29-
return zeroSize
30-
? style.getPropertyValue("overflow") !== "visible" ||
31-
// if 'overflow: visible' set, check if there is actually any overflow
32-
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
33-
: style.getPropertyValue("display") == "none";
3432
}
3533

3634
function visible(element) {

0 commit comments

Comments
 (0)