From 279de0e942eff7c56a3e3e12a756fcb1f6f18a1a Mon Sep 17 00:00:00 2001 From: Brendan Keogh Date: Mon, 19 Apr 2021 20:16:06 -0600 Subject: [PATCH 1/4] Adding a check to see if the element is a prototype of Element before getting the computed style --- src/helpers/tabbable.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/helpers/tabbable.js b/src/helpers/tabbable.js index f83f1480..8a64bd9a 100644 --- a/src/helpers/tabbable.js +++ b/src/helpers/tabbable.js @@ -18,6 +18,12 @@ 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)) { + return false; + } + // Otherwise we need to check some styles const style = window.getComputedStyle(element); return zeroSize From d7674ffd8d46c52bfc1611cdf57300a236ea7c01 Mon Sep 17 00:00:00 2001 From: Brendan Keogh Date: Thu, 27 May 2021 04:50:41 -0600 Subject: [PATCH 2/4] 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) { From dc81e829425184c2314cb0bca8b1f7d73dca52ee Mon Sep 17 00:00:00 2001 From: Brendan Keogh Date: Fri, 28 May 2021 07:44:51 -0600 Subject: [PATCH 3/4] Working on lint error --- src/helpers/tabbable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/tabbable.js b/src/helpers/tabbable.js index 8d7240c7..f149c9de 100644 --- a/src/helpers/tabbable.js +++ b/src/helpers/tabbable.js @@ -26,7 +26,8 @@ function hidesContents(element) { // if 'overflow: visible' set, check if there is actually any overflow (element.scrollWidth <= 0 && element.scrollHeight <= 0) : style.getPropertyValue("display") == "none"; - } catch(exception) { + } catch (exception) { + console.warn('Failed to inspect element style'); return false; } } From 42b029d3884a15054b8d31d13ded7edbb9e20df4 Mon Sep 17 00:00:00 2001 From: Brendan Keogh Date: Fri, 28 May 2021 08:10:15 -0600 Subject: [PATCH 4/4] Fixing lint error and PR suggestion change to use double quotes --- src/helpers/tabbable.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/tabbable.js b/src/helpers/tabbable.js index f149c9de..f2ebbc9c 100644 --- a/src/helpers/tabbable.js +++ b/src/helpers/tabbable.js @@ -27,7 +27,8 @@ function hidesContents(element) { (element.scrollWidth <= 0 && element.scrollHeight <= 0) : style.getPropertyValue("display") == "none"; } catch (exception) { - console.warn('Failed to inspect element style'); + // eslint-disable-next-line no-console + console.warn("Failed to inspect element style"); return false; } }