From df7adb45e3977ee93ddbb9eb087452bf78b872ae Mon Sep 17 00:00:00 2001 From: Lazyuki Date: Thu, 20 Dec 2018 10:00:27 -0500 Subject: [PATCH] fix: pass appear to CSSTransition callbacks (#441) Based on #144, but with working tests. Fixes #143. --- src/CSSTransition.js | 6 +-- test/CSSTransition-test.js | 91 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 3 deletions(-) diff --git a/src/CSSTransition.js b/src/CSSTransition.js index 8761d418..d697dd8a 100644 --- a/src/CSSTransition.js +++ b/src/CSSTransition.js @@ -130,7 +130,7 @@ class CSSTransition extends React.Component { addClass(node, className) if (this.props.onEnter) { - this.props.onEnter(node) + this.props.onEnter(node, appearing) } } @@ -142,7 +142,7 @@ class CSSTransition extends React.Component { this.reflowAndAddClass(node, activeClassName) if (this.props.onEntering) { - this.props.onEntering(node) + this.props.onEntering(node, appearing) } } @@ -153,7 +153,7 @@ class CSSTransition extends React.Component { addClass(node, doneClassName); if (this.props.onEntered) { - this.props.onEntered(node) + this.props.onEntered(node, appearing) } } diff --git a/test/CSSTransition-test.js b/test/CSSTransition-test.js index 6d4a1e40..b04fff16 100644 --- a/test/CSSTransition-test.js +++ b/test/CSSTransition-test.js @@ -113,6 +113,97 @@ describe('CSSTransition', () => { }); }); + describe('appearing', () => { + it('should apply appear classes at each transition state', done => { + let count = 0; + mount( + { + count++; + expect(isAppearing).toEqual(true); + expect(node.className).toEqual('appear-test-appear'); + }} + onEntering={(node, isAppearing) => { + count++; + expect(isAppearing).toEqual(true); + expect(node.className).toEqual('appear-test-appear appear-test-appear-active'); + }} + + onEntered={(node, isAppearing) => { + expect(isAppearing).toEqual(true); + expect(node.className).toEqual('appear-test-enter-done'); + expect(count).toEqual(2); + done(); + }} + > +
+ + ); + }); + + it('should not be appearing in normal enter mode', done => { + let count = 0; + mount( + +
+ + ).setProps({ + in: true, + + onEnter(node, isAppearing){ + count++; + expect(isAppearing).toEqual(false); + expect(node.className).toEqual('not-appear-test-enter'); + }, + + onEntering(node, isAppearing){ + count++; + expect(isAppearing).toEqual(false); + expect(node.className).toEqual('not-appear-test-enter not-appear-test-enter-active'); + }, + + onEntered(node, isAppearing){ + expect(isAppearing).toEqual(false); + expect(node.className).toEqual('not-appear-test-enter-done'); + expect(count).toEqual(2); + done(); + } + }); + }); + + it('should not enter the transition states when appear=false', () => { + mount( + { + throw Error('Enter called!') + }} + onEntering={() => { + throw Error('Entring called!') + }} + onEntered={() => { + throw Error('Entred called!') + }} + > +
+ + ); + }); + + + }); + describe('exiting', ()=> { let instance;