diff --git a/src/platforms/web/runtime/class-util.js b/src/platforms/web/runtime/class-util.js index 768f69d94e..709526c238 100644 --- a/src/platforms/web/runtime/class-util.js +++ b/src/platforms/web/runtime/class-util.js @@ -42,12 +42,20 @@ export function removeClass (el: HTMLElement, cls: ?string) { } else { el.classList.remove(cls) } + if (!el.classList.length) { + el.removeAttribute('class') + } } else { let cur = ` ${el.getAttribute('class') || ''} ` const tar = ' ' + cls + ' ' while (cur.indexOf(tar) >= 0) { cur = cur.replace(tar, ' ') } - el.setAttribute('class', cur.trim()) + cur = cur.trim() + if (cur) { + el.setAttribute('class', cur) + } else { + el.removeAttribute('class') + } } } diff --git a/src/platforms/web/runtime/components/transition-group.js b/src/platforms/web/runtime/components/transition-group.js index a02d7a6e9e..ffb6233087 100644 --- a/src/platforms/web/runtime/components/transition-group.js +++ b/src/platforms/web/runtime/components/transition-group.js @@ -127,7 +127,7 @@ export default { if (!hasTransition) { return false } - if (this._hasMove != null) { + if (this._hasMove) { return this._hasMove } // Detect whether an element with the move class applied has diff --git a/test/unit/features/transition/transition-group.spec.js b/test/unit/features/transition/transition-group.spec.js index 068512e834..0f40538f5b 100644 --- a/test/unit/features/transition/transition-group.spec.js +++ b/test/unit/features/transition/transition-group.spec.js @@ -293,5 +293,52 @@ if (!isIE9) { }).$mount() expect(' children must be keyed:
').toHaveBeenWarned() }) + + // Github issue #6006 + it('should work with dynamic name', done => { + const vm = new Vue({ + template: ` +
+ +
{{ item }}
+
+
+ `, + data: { + items: ['a', 'b', 'c'], + name: 'group' + } + }).$mount(el) + + vm.name = 'invalid-name' + vm.items = ['b', 'c', 'a'] + waitForUpdate(() => { + expect(vm.$el.innerHTML.replace(/\s?style=""(\s?)/g, '$1')).toBe( + `` + + `
b
` + + `
c
` + + `
a
` + + `
` + ) + vm.name = 'group' + vm.items = ['a', 'b', 'c'] + }).thenWaitFor(nextFrame).then(() => { + expect(vm.$el.innerHTML.replace(/\s?style=""(\s?)/g, '$1')).toBe( + `` + + `
a
` + + `
b
` + + `
c
` + + `
` + ) + }).thenWaitFor(duration * 2 + buffer).then(() => { + expect(vm.$el.innerHTML.replace(/\s?style=""(\s?)/g, '$1')).toBe( + `` + + `
a
` + + `
b
` + + `
c
` + + `
` + ) + }).then(done) + }) }) } diff --git a/test/unit/features/transition/transition.spec.js b/test/unit/features/transition/transition.spec.js index 2bb77e159f..753c4ee803 100644 --- a/test/unit/features/transition/transition.spec.js +++ b/test/unit/features/transition/transition.spec.js @@ -437,7 +437,7 @@ if (!isIE9) { expect(enterSpy).toHaveBeenCalled() expect(vm.$el.innerHTML).toBe('
foo
') }).thenWaitFor(nextFrame).then(() => { - expect(vm.$el.innerHTML).toMatch(/foo<\/div>/) + expect(vm.$el.innerHTML).toBe('
foo
') }).then(done) })