Skip to content

Commit 3a06c17

Browse files
authored
feat: make isVisible more comprehensive (#454)
1 parent 199f2d8 commit 3a06c17

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/utils/isElementVisible.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function isStyleVisible<T extends Element>(element: T) {
99
return false
1010
}
1111

12-
const { display, visibility, opacity } = element.style
12+
const { display, visibility, opacity } = getComputedStyle(element)
1313

1414
return (
1515
display !== 'none' &&

tests/isVisible.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,19 @@ describe('isVisible', () => {
109109
expect(wrapper.html()).toContain('Item: 1')
110110
expect(wrapper.html()).not.toContain('Item: 2')
111111
})
112+
113+
it('should take css into account', async () => {
114+
const style = document.createElement('style')
115+
style.type = 'text/css'
116+
document.head.appendChild(style)
117+
style.sheet!.insertRule('.opacity-0 { opacity: 0; }')
118+
119+
const wrapper = mount({
120+
template: '<div id="my-div" class="opacity-0" />'
121+
})
122+
123+
expect(wrapper.get('#my-div').isVisible()).toBe(false)
124+
125+
document.head.removeChild(style)
126+
})
112127
})

0 commit comments

Comments
 (0)