Skip to content

Commit 9c1967e

Browse files
committed
Merge pull request vuejs#1246 from nkovacs/1241-in-out-fix
Don't set up css transition callback if there's a js callback.
2 parents 5705239 + b8b489e commit 9c1967e

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

src/transition/transition.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,20 @@ p.enterNextTick = function () {
9595
_.nextTick(function () {
9696
this.justEntered = false
9797
}, this)
98-
var type = this.getCssTransitionType(this.enterClass)
9998
var enterDone = this.enterDone
100-
if (type === TYPE_TRANSITION) {
101-
// trigger transition by removing enter class now
99+
var type = this.getCssTransitionType(this.enterClass)
100+
if (!this.pendingJsCb) {
101+
if (type === TYPE_TRANSITION) {
102+
// trigger transition by removing enter class now
103+
removeClass(this.el, this.enterClass)
104+
this.setupCssCb(transitionEndEvent, enterDone)
105+
} else if (type === TYPE_ANIMATION) {
106+
this.setupCssCb(animationEndEvent, enterDone)
107+
} else {
108+
enterDone()
109+
}
110+
} else if (type === TYPE_TRANSITION) {
102111
removeClass(this.el, this.enterClass)
103-
this.setupCssCb(transitionEndEvent, enterDone)
104-
} else if (type === TYPE_ANIMATION) {
105-
this.setupCssCb(animationEndEvent, enterDone)
106-
} else if (!this.pendingJsCb) {
107-
enterDone()
108112
}
109113
}
110114

test/unit/specs/transition/transition_spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,50 @@ if (_.inBrowser && !_.isIE9) {
342342
}
343343
})
344344

345+
it('css + js hook with callback before transitionend', function (done) {
346+
document.body.removeChild(el)
347+
el.classList.add('test')
348+
349+
// enter hook that expects a second argument
350+
// indicates the user wants to control when the
351+
// transition ends.
352+
var enterCalled = false
353+
hooks.enter = function (el, enterDone) {
354+
enterCalled = true
355+
setTimeout(function () {
356+
enterDone()
357+
testDone()
358+
}, 20)
359+
}
360+
361+
el.__v_trans = new Transition(el, 'test', hooks, vm)
362+
transition.apply(el, 1, function () {
363+
document.body.appendChild(el)
364+
op()
365+
}, vm, cb)
366+
expect(hooks.beforeEnter).toHaveBeenCalled()
367+
expect(op).toHaveBeenCalled()
368+
expect(cb).not.toHaveBeenCalled()
369+
expect(enterCalled).toBe(true)
370+
_.nextTick(function () {
371+
expect(el.classList.contains('test-enter')).toBe(false)
372+
expect(hooks.afterEnter).not.toHaveBeenCalled()
373+
_.on(el, _.transitionEndEvent, function () {
374+
// callback should have been called, but only once, by the js callback
375+
expect(cb).toHaveBeenCalled()
376+
expect(cb.calls.count()).toBe(1)
377+
expect(hooks.afterEnter).toHaveBeenCalled()
378+
done()
379+
})
380+
})
381+
382+
// this is called by the enter hook
383+
function testDone () {
384+
expect(cb).toHaveBeenCalled()
385+
expect(hooks.afterEnter).toHaveBeenCalled()
386+
}
387+
})
388+
345389
it('clean up unfinished css callback', function (done) {
346390
el.__v_trans = new Transition(el, 'test', null, vm)
347391
el.classList.add('test')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy