Skip to content

Commit df7adb4

Browse files
Lazyukijquense
authored andcommitted
fix: pass appear to CSSTransition callbacks (#441)
Based on #144, but with working tests. Fixes#143.
1 parent 69a45c4 commit df7adb4

2 files changed

Lines changed: 94 additions & 3 deletions

File tree

‎src/CSSTransition.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class CSSTransition extends React.Component {
130130
addClass(node,className)
131131

132132
if(this.props.onEnter){
133-
this.props.onEnter(node)
133+
this.props.onEnter(node,appearing)
134134
}
135135
}
136136

@@ -142,7 +142,7 @@ class CSSTransition extends React.Component {
142142
this.reflowAndAddClass(node,activeClassName)
143143

144144
if(this.props.onEntering){
145-
this.props.onEntering(node)
145+
this.props.onEntering(node,appearing)
146146
}
147147
}
148148

@@ -153,7 +153,7 @@ class CSSTransition extends React.Component {
153153
addClass(node,doneClassName);
154154

155155
if(this.props.onEntered){
156-
this.props.onEntered(node)
156+
this.props.onEntered(node,appearing)
157157
}
158158
}
159159

‎test/CSSTransition-test.js‎

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,97 @@ describe('CSSTransition', () => {
113113
});
114114
});
115115

116+
describe('appearing',()=>{
117+
it('should apply appear classes at each transition state',done=>{
118+
letcount=0;
119+
mount(
120+
<CSSTransition
121+
timeout={10}
122+
classNames='appear-test'
123+
in={true}
124+
appear={true}
125+
onEnter={(node,isAppearing)=>{
126+
count++;
127+
expect(isAppearing).toEqual(true);
128+
expect(node.className).toEqual('appear-test-appear');
129+
}}
130+
onEntering={(node,isAppearing)=>{
131+
count++;
132+
expect(isAppearing).toEqual(true);
133+
expect(node.className).toEqual('appear-test-appear appear-test-appear-active');
134+
}}
135+
136+
onEntered={(node,isAppearing)=>{
137+
expect(isAppearing).toEqual(true);
138+
expect(node.className).toEqual('appear-test-enter-done');
139+
expect(count).toEqual(2);
140+
done();
141+
}}
142+
>
143+
<div/>
144+
</CSSTransition>
145+
);
146+
});
147+
148+
it('should not be appearing in normal enter mode',done=>{
149+
letcount=0;
150+
mount(
151+
<CSSTransition
152+
timeout={10}
153+
classNames='not-appear-test'
154+
appear={true}
155+
>
156+
<div/>
157+
</CSSTransition>
158+
).setProps({
159+
in: true,
160+
161+
onEnter(node,isAppearing){
162+
count++;
163+
expect(isAppearing).toEqual(false);
164+
expect(node.className).toEqual('not-appear-test-enter');
165+
},
166+
167+
onEntering(node,isAppearing){
168+
count++;
169+
expect(isAppearing).toEqual(false);
170+
expect(node.className).toEqual('not-appear-test-enter not-appear-test-enter-active');
171+
},
172+
173+
onEntered(node,isAppearing){
174+
expect(isAppearing).toEqual(false);
175+
expect(node.className).toEqual('not-appear-test-enter-done');
176+
expect(count).toEqual(2);
177+
done();
178+
}
179+
});
180+
});
181+
182+
it('should not enter the transition states when appear=false',()=>{
183+
mount(
184+
<CSSTransition
185+
timeout={10}
186+
classNames='appear-fail-test'
187+
in={true}
188+
appear={false}
189+
onEnter={()=>{
190+
throwError('Enter called!')
191+
}}
192+
onEntering={()=>{
193+
throwError('Entring called!')
194+
}}
195+
onEntered={()=>{
196+
throwError('Entred called!')
197+
}}
198+
>
199+
<div/>
200+
</CSSTransition>
201+
);
202+
});
203+
204+
205+
});
206+
116207
describe('exiting',()=>{
117208
letinstance;
118209

0 commit comments

Comments
 (0)