Skip to content

Commit 6977109

Browse files
committed
improve transition-group move detection (fix #4900, close #4911)
1 parent ef57aa2 commit 6977109

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

Diff for: src/platforms/web/runtime/components/transition-group.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
// nodes will remain where they should be.
1313

1414
import { warn, extend } from 'core/util/index'
15+
import { addClass, removeClass } from '../class-util'
1516
import { transitionProps, extractTransitionData } from './transition'
17+
1618
import {
1719
hasTransition,
18-
addTransitionClass,
19-
removeTransitionClass,
2020
getTransitionInfo,
21-
transitionEndEvent
21+
transitionEndEvent,
22+
addTransitionClass,
23+
removeTransitionClass
2224
} from '../transition-util'
2325

2426
const props = extend({
@@ -122,17 +124,28 @@ export default {
122124
},
123125

124126
methods: {
125-
hasMove (el: Element, moveClass: string): boolean {
127+
hasMove (el: any, moveClass: string): boolean {
126128
/* istanbul ignore if */
127129
if (!hasTransition) {
128130
return false
129131
}
130132
if (this._hasMove != null) {
131133
return this._hasMove
132134
}
133-
addTransitionClass(el, moveClass)
134-
const info = getTransitionInfo(el)
135-
removeTransitionClass(el, moveClass)
135+
// Detect whether an element with the move class applied has
136+
// CSS transitions. Since the element may be inside an entering
137+
// transition at this very moment, we make a clone of it and remove
138+
// all other transition classes applied to ensure only the move class
139+
// is applied.
140+
const clone = el.cloneNode()
141+
if (el._transitionClasses) {
142+
el._transitionClasses.forEach(cls => { removeClass(clone, cls) })
143+
}
144+
addClass(clone, moveClass)
145+
clone.style.display = 'none'
146+
this.$el.appendChild(clone)
147+
const info = getTransitionInfo(clone)
148+
this.$el.removeChild(clone)
136149
return (this._hasMove = info.hasTransform)
137150
}
138151
}

0 commit comments

Comments
 (0)