Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b9c4870

Browse filesBrowse files
authored
feat: make isVisible more comprehensive (backport from v2) (fix #1456) (#2013)
* feat: make isVisible more comprehensive (backport from v2) * feat: make isVisible more comprehensive (backport from v2)
1 parent c6d28ef commit b9c4870
Copy full SHA for b9c4870

File tree

2 files changed

+24
-1
lines changed
Filter options

2 files changed

+24
-1
lines changed

‎packages/shared/is-visible.js

Copy file name to clipboardExpand all lines: packages/shared/is-visible.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
*/
66

77
function isStyleVisible(element) {
8-
const { display, visibility, opacity } = element.style
8+
if (!(element instanceof HTMLElement) && !(element instanceof SVGElement)) {
9+
return false
10+
}
11+
12+
// Per https://lists.w3.org/Archives/Public/www-style/2018May/0031.html
13+
// getComputedStyle should only work with connected elements.
14+
const { display, visibility, opacity } = element.isConnected
15+
? getComputedStyle(element)
16+
: element.style
917
return (
1018
display !== 'none' &&
1119
visibility !== 'hidden' &&

‎test/specs/wrapper/isVisible.spec.js

Copy file name to clipboardExpand all lines: test/specs/wrapper/isVisible.spec.js
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,19 @@ describeWithShallowAndMount('isVisible', mountingMethod => {
176176

177177
expect(wrapper.find('.child.ready').isVisible()).toEqual(true)
178178
})
179+
180+
it('returns false if element has class with opacity: 0', async () => {
181+
const style = document.createElement('style')
182+
style.type = 'text/css'
183+
document.head.appendChild(style)
184+
style.sheet.insertRule('.opacity-0 { opacity: 0; }')
185+
186+
const compiled = compileToFunctions('<div id="my-div" class="opacity-0" />')
187+
const wrapper = mountingMethod(compiled, {
188+
attachTo: document.body
189+
})
190+
expect(wrapper.get('#my-div').isVisible()).toBe(false)
191+
192+
document.head.removeChild(style)
193+
})
179194
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.