Merge branch 'bugfix/v-show-not-respecting-orig-display' of git://github.com/chrisvfritz/vue into show-display

This commit is contained in:
Evan You 2016-08-11 08:48:44 -05:00
commit 837b0b224b
2 changed files with 13 additions and 3 deletions

View File

@ -17,7 +17,9 @@ export default {
if (value && transition && transition.appear && !isIE9) {
enter(vnode)
}
el.style.display = value ? '' : 'none'
const originalDisplay = el.style.display
el.style.display = value ? originalDisplay : 'none'
el.__vOriginalDisplay = originalDisplay
},
update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) {
/* istanbul ignore if */
@ -27,14 +29,14 @@ export default {
if (transition && !isIE9) {
if (value) {
enter(vnode)
el.style.display = ''
el.style.display = el.__vOriginalDisplay
} else {
leave(vnode, () => {
el.style.display = 'none'
})
}
} else {
el.style.display = value ? '' : 'none'
el.style.display = value ? el.__vOriginalDisplay : 'none'
}
}
}

View File

@ -49,4 +49,12 @@ describe('Directive v-show', () => {
expect(vm.$el.firstChild.style.display).toBe('')
}).then(done)
})
it('should respect display value in style attribute', () => {
const vm = new Vue({
template: '<div><span v-show="foo" style="display:block">hello</span></div>',
data: { foo: true }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('block')
})
})