Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions packages/shared/is-visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
}

Expand Down
15 changes: 15 additions & 0 deletions test/specs/wrapper/isVisible.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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('<div id="my-div" class="opacity-0" />')
const wrapper = mountingMethod(compiled, {
attachTo: document.body
})
expect(wrapper.get('#my-div').isVisible()).toBe(false)

document.head.removeChild(style)
})
})