Skip to content

Commit 543ff97

Browse files
committed
Merge branch 'show-display' into next
2 parents 7b42671 + 86bf3da commit 543ff97

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/platforms/web/runtime/directives/show.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,32 @@ function locateNode (vnode: VNode): VNodeWithData {
1111
}
1212

1313
export default {
14-
bind (el: HTMLElement, { value }: VNodeDirective, vnode: VNodeWithData) {
14+
bind (el: any, { value }: VNodeDirective, vnode: VNodeWithData) {
1515
vnode = locateNode(vnode)
1616
const transition = vnode.data && vnode.data.transition
1717
if (value && transition && transition.appear && !isIE9) {
1818
enter(vnode)
1919
}
20-
el.style.display = value ? '' : 'none'
20+
const originalDisplay = el.style.display
21+
el.style.display = value ? originalDisplay : 'none'
22+
el.__vOriginalDisplay = originalDisplay
2123
},
22-
update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) {
24+
update (el: any, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) {
2325
/* istanbul ignore if */
2426
if (value === oldValue) return
2527
vnode = locateNode(vnode)
2628
const transition = vnode.data && vnode.data.transition
2729
if (transition && !isIE9) {
2830
if (value) {
2931
enter(vnode)
30-
el.style.display = ''
32+
el.style.display = el.__vOriginalDisplay
3133
} else {
3234
leave(vnode, () => {
3335
el.style.display = 'none'
3436
})
3537
}
3638
} else {
37-
el.style.display = value ? '' : 'none'
39+
el.style.display = value ? el.__vOriginalDisplay : 'none'
3840
}
3941
}
4042
}

test/unit/features/directives/show.spec.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,19 @@ describe('Directive v-show', () => {
4949
expect(vm.$el.firstChild.style.display).toBe('')
5050
}).then(done)
5151
})
52+
53+
it('should respect display value in style attribute', done => {
54+
const vm = new Vue({
55+
template: '<div><span v-show="foo" style="display:block">hello</span></div>',
56+
data: { foo: true }
57+
}).$mount()
58+
expect(vm.$el.firstChild.style.display).toBe('block')
59+
vm.foo = false
60+
waitForUpdate(() => {
61+
expect(vm.$el.firstChild.style.display).toBe('none')
62+
vm.foo = true
63+
}).then(() => {
64+
expect(vm.$el.firstChild.style.display).toBe('block')
65+
}).then(done)
66+
})
5267
})

0 commit comments

Comments
 (0)