From 17774cee9c71c8b223b1a144d7b01889d9ca1328 Mon Sep 17 00:00:00 2001 From: Alexander Fedyashov Date: Sun, 3 Dec 2017 10:07:09 +0200 Subject: [PATCH] fix(Transition): fix of the choice of duration --- src/modules/Transition/Transition.js | 5 ++- .../modules/Transition/Transition-test.js | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/modules/Transition/Transition.js b/src/modules/Transition/Transition.js index f9eea71ec5..aca1e41594 100644 --- a/src/modules/Transition/Transition.js +++ b/src/modules/Transition/Transition.js @@ -160,8 +160,11 @@ export default class Transition extends Component { this.nextStatus = null this.setSafeState({ status, animating: true }, () => { + const durationType = TRANSITION_TYPE[status] + const durationValue = normalizeTransitionDuration(duration, durationType) + _.invoke(this.props, 'onStart', null, { ...this.props, status }) - setTimeout(this.handleComplete, normalizeTransitionDuration(duration, 'show')) + setTimeout(this.handleComplete, durationValue) }) } diff --git a/test/specs/modules/Transition/Transition-test.js b/test/specs/modules/Transition/Transition-test.js index 84f6b5eab8..1e6cf71949 100644 --- a/test/specs/modules/Transition/Transition-test.js +++ b/test/specs/modules/Transition/Transition-test.js @@ -327,6 +327,28 @@ describe('Transition', () => { ) wrapper.setProps({ visible: false }) }) + + it('depends on the specified duration', (done) => { + const onHide = sandbox.spy() + wrapperMount( + +

+ , + ) + + wrapper.setProps({ visible: false }) + wrapper.should.have.state('status', Transition.EXITING) + + setTimeout(() => { + wrapper.should.have.state('status', Transition.EXITING) + }, 100) + setTimeout(() => { + onHide.should.have.been.calledOnce() + wrapper.should.have.state('status', Transition.EXITED) + + done() + }, 200) + }) }) describe('onShow', () => { @@ -351,6 +373,27 @@ describe('Transition', () => { , ) }) + + it('depends on the specified duration', (done) => { + const onShow = sandbox.spy() + wrapperMount( + +

+ , + ) + + wrapper.should.have.state('status', Transition.ENTERING) + + setTimeout(() => { + wrapper.should.have.state('status', Transition.ENTERING) + }, 100) + setTimeout(() => { + onShow.should.have.been.calledOnce() + wrapper.should.have.state('status', Transition.ENTERED) + + done() + }, 200) + }) }) describe('onStart', () => {