Skip to content

fix(v-show): display is not correct after v-show unbind (fix #11984) #12344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/platforms/web/runtime/directives/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default {
oldVnode: VNodeWithData,
isDestroy: boolean
) {
if (!isDestroy) {
if (!isDestroy && el.style.display === 'none') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that if the style is set to anything manually via style="display: none" or with :style, it should probably keep it as well

el.style.display = el.__vOriginalDisplay
}
}
Expand Down
28 changes: 28 additions & 0 deletions test/unit/features/directives/show.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,32 @@ describe('Directive v-show', () => {
expect(vm.$el.firstChild.style.display).toBe('none')
}).then(done)
})

it('should set display correctly when unbind with falsy', done => {
const vm = new Vue({
template:
'<div v-if="tester" v-show="false" style="display: block"></div>' +
'<div v-else style="display: flex"></div>',
data: { tester: true }
}).$mount()
expect(vm.$el.style.display).toBe('none')
vm.tester = false
waitForUpdate(() => {
expect(vm.$el.style.display).toBe('flex')
}).then(done)
})

it('should set display correctly when unbind with truthy', done => {
const vm = new Vue({
template:
'<div v-if="tester" v-show="true"></div>' +
'<div v-else style="display: flex"></div>',
data: { tester: true }
}).$mount()
expect(vm.$el.style.display).toBe('')
vm.tester = false
waitForUpdate(() => {
expect(vm.$el.style.display).toBe('flex')
}).then(done)
})
})