From 105175b26e32744d116309a2bf99f5f6620c30f4 Mon Sep 17 00:00:00 2001 From: Matthew Lieder Date: Fri, 30 Sep 2022 09:33:35 -0500 Subject: [PATCH 1/2] feat: make isVisible more comprehensive (backport from v2) --- packages/shared/is-visible.js | 13 ++++++++++--- test/specs/wrapper/isVisible.spec.js | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/shared/is-visible.js b/packages/shared/is-visible.js index 3f9030151..fc587dcb8 100644 --- a/packages/shared/is-visible.js +++ b/packages/shared/is-visible.js @@ -5,13 +5,20 @@ */ function isStyleVisible(element) { - const { display, visibility, opacity } = element.style + if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) { + return false + } + + // Per https://lists.w3.org/Archives/Public/www-style/2018May/0031.html + // getComputedStyle should only work with connected elements. + const { display, visibility, opacity } = element.isConnected + ? getComputedStyle(element) + : element.style return ( display !== 'none' && visibility !== 'hidden' && visibility !== 'collapse' && - opacity !== '0' && - opacity !== 0 + opacity !== '0' ) } diff --git a/test/specs/wrapper/isVisible.spec.js b/test/specs/wrapper/isVisible.spec.js index 9c6b0478d..bd6708771 100644 --- a/test/specs/wrapper/isVisible.spec.js +++ b/test/specs/wrapper/isVisible.spec.js @@ -176,4 +176,19 @@ describeWithShallowAndMount('isVisible', mountingMethod => { expect(wrapper.find('.child.ready').isVisible()).toEqual(true) }) + + it('returns false if element has class with opacity: 0', async () => { + const style = document.createElement('style') + style.type = 'text/css' + document.head.appendChild(style) + style.sheet.insertRule('.opacity-0 { opacity: 0; }') + + const compiled = compileToFunctions('
') + const wrapper = mountingMethod(compiled, { + attachTo: document.body + }) + expect(wrapper.get('#my-div').isVisible()).toBe(false) + + document.head.removeChild(style) + }) }) From 6676c3e018ae89e15c43fa59e70f0cf724610bdf Mon Sep 17 00:00:00 2001 From: Matthew Lieder Date: Mon, 17 Oct 2022 09:08:11 -0500 Subject: [PATCH 2/2] feat: make isVisible more comprehensive (backport from v2) --- packages/shared/is-visible.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/shared/is-visible.js b/packages/shared/is-visible.js index fc587dcb8..a7d52f379 100644 --- a/packages/shared/is-visible.js +++ b/packages/shared/is-visible.js @@ -18,7 +18,8 @@ function isStyleVisible(element) { display !== 'none' && visibility !== 'hidden' && visibility !== 'collapse' && - opacity !== '0' + opacity !== '0' && + opacity !== 0 ) }