Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CSSTransition appear #441

Merged
merged 1 commit into from Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/CSSTransition.js
Expand Up @@ -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)
}
}

Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
91 changes: 91 additions & 0 deletions test/CSSTransition-test.js
Expand Up @@ -113,6 +113,97 @@ describe('CSSTransition', () => {
});
});

describe('appearing', () => {
it('should apply appear classes at each transition state', done => {
let count = 0;
mount(
<CSSTransition
timeout={10}
classNames='appear-test'
in={true}
appear={true}
onEnter={(node, isAppearing) => {
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();
}}
>
<div/>
</CSSTransition>
);
});

it('should not be appearing in normal enter mode', done => {
let count = 0;
mount(
<CSSTransition
timeout={10}
classNames='not-appear-test'
appear={true}
>
<div/>
</CSSTransition>
).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(
<CSSTransition
timeout={10}
classNames='appear-fail-test'
in={true}
appear={false}
onEnter={() => {
throw Error('Enter called!')
}}
onEntering={() => {
throw Error('Entring called!')
}}
onEntered={() => {
throw Error('Entred called!')
}}
>
<div/>
</CSSTransition>
);
});


});

describe('exiting', ()=> {
let instance;

Expand Down