Skip to content

Commit

Permalink
Wrapping getComputedStyle in try catch per PR review
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankeogh-sf authored and diasbruno committed Jun 1, 2021
1 parent 31d59b2 commit 7e732d7
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/helpers/tabbable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ function hidesContents(element) {
// If the node is empty, this is good enough
if (zeroSize && !element.innerHTML) return true;

// if the element is not of type Element e.g. shadowRoot
// we cannot go any further
if (!element.isPrototypeOf(Element)) {
try {
// Otherwise we need to check some styles
const style = window.getComputedStyle(element);
return zeroSize
? style.getPropertyValue("overflow") !== "visible" ||
// if 'overflow: visible' set, check if there is actually any overflow
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
: style.getPropertyValue("display") == "none";
} catch(exception) {
return false;
}

// Otherwise we need to check some styles
const style = window.getComputedStyle(element);
return zeroSize
? style.getPropertyValue("overflow") !== "visible" ||
// if 'overflow: visible' set, check if there is actually any overflow
(element.scrollWidth <= 0 && element.scrollHeight <= 0)
: style.getPropertyValue("display") == "none";
}

function visible(element) {
Expand Down

0 comments on commit 7e732d7

Please sign in to comment.