From a4ac2eb687e909f446400c2b629963d5f6d26ed2 Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Fri, 5 Aug 2016 19:49:48 -0400 Subject: [PATCH 1/3] made v-show respect display values in style attributes --- src/platforms/web/runtime/directives/show.js | 8 +++++--- test/unit/features/directives/show.spec.js | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/directives/show.js b/src/platforms/web/runtime/directives/show.js index 603d8056..4a602125 100644 --- a/src/platforms/web/runtime/directives/show.js +++ b/src/platforms/web/runtime/directives/show.js @@ -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.dataset.__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.dataset.__vOriginalDisplay } else { leave(vnode, () => { el.style.display = 'none' }) } } else { - el.style.display = value ? '' : 'none' + el.style.display = value ? el.dataset.__vOriginalDisplay : 'none' } } } diff --git a/test/unit/features/directives/show.spec.js b/test/unit/features/directives/show.spec.js index e9d4e0b9..21175d8a 100644 --- a/test/unit/features/directives/show.spec.js +++ b/test/unit/features/directives/show.spec.js @@ -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: '
hello
', + data: { foo: true } + }).$mount() + expect(vm.$el.firstChild.style.display).toBe('block') + }) }) From dcd14696b3721e15b618faeda2696067071b1a2b Mon Sep 17 00:00:00 2001 From: Chris Fritz Date: Mon, 8 Aug 2016 18:00:59 -0400 Subject: [PATCH 2/3] store v-show original display value directly on el --- src/platforms/web/runtime/directives/show.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/directives/show.js b/src/platforms/web/runtime/directives/show.js index 4a602125..b4fb45d7 100644 --- a/src/platforms/web/runtime/directives/show.js +++ b/src/platforms/web/runtime/directives/show.js @@ -19,7 +19,7 @@ export default { } const originalDisplay = el.style.display el.style.display = value ? originalDisplay : 'none' - el.dataset.__vOriginalDisplay = originalDisplay + el.__vOriginalDisplay = originalDisplay }, update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) { /* istanbul ignore if */ @@ -29,14 +29,14 @@ export default { if (transition && !isIE9) { if (value) { enter(vnode) - el.style.display = el.dataset.__vOriginalDisplay + el.style.display = el.__vOriginalDisplay } else { leave(vnode, () => { el.style.display = 'none' }) } } else { - el.style.display = value ? el.dataset.__vOriginalDisplay : 'none' + el.style.display = value ? el.__vOriginalDisplay : 'none' } } } From 86bf3da18e29cbec2ff9c88f8ff39e2eefe3e168 Mon Sep 17 00:00:00 2001 From: Evan You Date: Thu, 11 Aug 2016 08:53:31 -0500 Subject: [PATCH 3/3] fix flow error for #3393 --- src/platforms/web/runtime/directives/show.js | 4 ++-- test/unit/features/directives/show.spec.js | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/platforms/web/runtime/directives/show.js b/src/platforms/web/runtime/directives/show.js index b4fb45d7..44c00979 100644 --- a/src/platforms/web/runtime/directives/show.js +++ b/src/platforms/web/runtime/directives/show.js @@ -11,7 +11,7 @@ function locateNode (vnode: VNode): VNodeWithData { } export default { - bind (el: HTMLElement, { value }: VNodeDirective, vnode: VNodeWithData) { + bind (el: any, { value }: VNodeDirective, vnode: VNodeWithData) { vnode = locateNode(vnode) const transition = vnode.data && vnode.data.transition if (value && transition && transition.appear && !isIE9) { @@ -21,7 +21,7 @@ export default { el.style.display = value ? originalDisplay : 'none' el.__vOriginalDisplay = originalDisplay }, - update (el: HTMLElement, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) { + update (el: any, { value, oldValue }: VNodeDirective, vnode: VNodeWithData) { /* istanbul ignore if */ if (value === oldValue) return vnode = locateNode(vnode) diff --git a/test/unit/features/directives/show.spec.js b/test/unit/features/directives/show.spec.js index 21175d8a..fd0db03e 100644 --- a/test/unit/features/directives/show.spec.js +++ b/test/unit/features/directives/show.spec.js @@ -50,11 +50,18 @@ describe('Directive v-show', () => { }).then(done) }) - it('should respect display value in style attribute', () => { + it('should respect display value in style attribute', done => { const vm = new Vue({ template: '
hello
', data: { foo: true } }).$mount() expect(vm.$el.firstChild.style.display).toBe('block') + vm.foo = false + waitForUpdate(() => { + expect(vm.$el.firstChild.style.display).toBe('none') + vm.foo = true + }).then(() => { + expect(vm.$el.firstChild.style.display).toBe('block') + }).then(done) }) })