@@ -63,15 +63,17 @@ export default class ReactCSSTransitionReplace extends React.Component {
63
63
transitionAppearTimeout : createTransitionTimeoutPropValidator ( 'Appear' ) ,
64
64
transitionEnterTimeout : createTransitionTimeoutPropValidator ( 'Enter' ) ,
65
65
transitionLeaveTimeout : createTransitionTimeoutPropValidator ( 'Leave' ) ,
66
- overflowHidden : React . PropTypes . bool
66
+ overflowHidden : React . PropTypes . bool ,
67
+ changeWidth : React . PropTypes . bool
67
68
} ;
68
69
69
70
static defaultProps = {
70
71
transitionAppear : false ,
71
72
transitionEnter : true ,
72
73
transitionLeave : true ,
73
74
overflowHidden : true ,
74
- component : 'span'
75
+ component : 'span' ,
76
+ changeWidth : false
75
77
} ;
76
78
77
79
state = {
@@ -80,6 +82,7 @@ export default class ReactCSSTransitionReplace extends React.Component {
80
82
nextChild : undefined ,
81
83
nextChildKey : '' ,
82
84
height : null ,
85
+ width : null ,
83
86
isLeaving : false
84
87
} ;
85
88
@@ -118,7 +121,8 @@ export default class ReactCSSTransitionReplace extends React.Component {
118
121
this . setState ( {
119
122
nextChild,
120
123
nextChildKey : state . currentChildKey ? String ( Number ( state . currentChildKey ) + 1 ) : '1' ,
121
- height : state . currentChild ? ReactDOM . findDOMNode ( this . refs . curr ) . offsetHeight : 0
124
+ height : state . currentChild ? ReactDOM . findDOMNode ( this . refs . curr ) . offsetHeight : 0 ,
125
+ width : state . currentChild && this . props . changeWidth ? ReactDOM . findDOMNode ( this . refs . curr ) . offsetWidth : null
122
126
} ) ;
123
127
124
128
// Enqueue setting the next height to trigger the height transition.
@@ -141,12 +145,18 @@ export default class ReactCSSTransitionReplace extends React.Component {
141
145
enqueueHeightTransition ( nextChild , tickCount = 0 ) {
142
146
this . timeout = setTimeout ( ( ) => {
143
147
if ( ! nextChild ) {
144
- return this . setState ( { height : 0 } ) ;
148
+ return this . setState ( {
149
+ height : 0 ,
150
+ width : this . props . changeWidth ? 0 : null
151
+ } ) ;
145
152
}
146
153
147
154
const nextNode = ReactDOM . findDOMNode ( this . refs . next ) ;
148
155
if ( nextNode ) {
149
- this . setState ( { height : nextNode . offsetHeight } ) ;
156
+ this . setState ( {
157
+ height : nextNode . offsetHeight ,
158
+ width : this . props . changeWidth ? nextNode . offsetWidth : null
159
+ } ) ;
150
160
}
151
161
else {
152
162
// The DOM hasn't rendered the entering element yet, so wait another tick.
@@ -181,7 +191,8 @@ export default class ReactCSSTransitionReplace extends React.Component {
181
191
currentChildKey : state . nextChildKey ,
182
192
nextChild : undefined ,
183
193
nextChildKey : '' ,
184
- height : null
194
+ height : null ,
195
+ width : null
185
196
} ) ;
186
197
}
187
198
@@ -200,6 +211,7 @@ export default class ReactCSSTransitionReplace extends React.Component {
200
211
if ( ! this . state . nextChild ) {
201
212
this . isTransitioning = false ;
202
213
state . height = null ;
214
+ state . width = null ;
203
215
}
204
216
205
217
this . setState ( state ) ;
@@ -212,7 +224,8 @@ export default class ReactCSSTransitionReplace extends React.Component {
212
224
return this . setState ( {
213
225
nextChild : undefined ,
214
226
nextChildKey : '' ,
215
- height : null
227
+ height : null ,
228
+ width : null
216
229
} ) ;
217
230
}
218
231
@@ -240,11 +253,11 @@ export default class ReactCSSTransitionReplace extends React.Component {
240
253
}
241
254
242
255
render ( ) {
243
- const { currentChild, currentChildKey, nextChild, nextChildKey, height, isLeaving } = this . state ;
256
+ const { currentChild, currentChildKey, nextChild, nextChildKey, height, width , isLeaving } = this . state ;
244
257
const childrenToRender = [ ] ;
245
258
246
259
const { overflowHidden, transitionName, component,
247
- transitionAppear, transitionEnter, transitionLeave,
260
+ transitionAppear, transitionEnter, transitionLeave, changeWidth ,
248
261
transitionAppearTimeout, transitionEnterTimeout, transitionLeaveTimeout,
249
262
...containerProps } = this . props ;
250
263
@@ -277,6 +290,10 @@ export default class ReactCSSTransitionReplace extends React.Component {
277
290
if ( overflowHidden ) {
278
291
containerProps . style . overflow = 'hidden' ;
279
292
}
293
+
294
+ if ( changeWidth ) {
295
+ containerProps . style . width = width ;
296
+ }
280
297
}
281
298
282
299
if ( nextChild ) {
0 commit comments