From 7e732d73f7195f3db09f3e58f7918f0b2d24d323 Mon Sep 17 00:00:00 2001 From: Brendan Keogh Date: Thu, 27 May 2021 04:50:41 -0600 Subject: [PATCH] Wrapping getComputedStyle in try catch per PR review --- src/helpers/tabbable.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/helpers/tabbable.js b/src/helpers/tabbable.js index 8a64bd9a..8d7240c7 100644 --- a/src/helpers/tabbable.js +++ b/src/helpers/tabbable.js @@ -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) {