Skip to content
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

made v-show respect display values in style attributes #3393

Merged
merged 2 commits into from
Aug 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/platforms/web/runtime/directives/show.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

flow doesn't allow attaching properties to HTMLElements, let's just declare el's type as any in the function signatures to make it pass.

},
update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) {
/* istanbul ignore if */
Expand All @@ -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'
}
}
}
8 changes: 8 additions & 0 deletions test/unit/features/directives/show.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
})