Skip to content

Commit 8cb2812

Browse files
committed
Merge pull request facebook#1941 from divad12/animating-one-or-zero-items-docs
Clarify animating one or zero items in animation docs
2 parents 673e228 + 721f397 commit 8cb2812

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/docs/09.1-animation.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,35 @@ You'll notice that when you try to remove an item `ReactCSSTransitionGroup` keep
8484
}
8585
```
8686

87+
### Animating One or Zero Items
88+
89+
Although in the example above we rendered a list of items into `ReactCSSTransitionGroup`, the children of `ReactCSSTransitionGroup` can be one or zero items. This makes it possible to animate a single element entering or leaving. Similarly, you can animate a new element replacing the current element, with the new element animating in while the current animates out. For example, we can implement a simple image carousel like this:
90+
91+
```javascript{12-14}
92+
/** @jsx React.DOM */
93+
94+
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
95+
96+
var ImageCarousel = React.createClass({
97+
propTypes: {
98+
imageSrc: React.PropTypes.string.isRequired
99+
},
100+
render: function() {
101+
return (
102+
<div>
103+
<ReactCSSTransitionGroup transitionName="carousel">
104+
<img src={this.props.imageSrc} key={this.props.imageSrc} />
105+
</ReactCSSTransitionGroup>
106+
</div>
107+
);
108+
}
109+
});
110+
```
111+
112+
> Note:
113+
>
114+
> You must provide [the `key` attribute](/react/docs/multiple-components.html#dynamic-children) for all children of `ReactCSSTransitionGroup`, even if rendering a single item. This is how React will determine which children have entered, left, or stayed.
115+
87116
### Disabling Animations
88117

89118
You can disable animating `enter` or `leave` animations if you want. For example, sometimes you may want an `enter` animation and no `leave` animation, but `ReactCSSTransitionGroup` waits for an animation to complete before removing your DOM node. You can add `transitionEnter={false}` or `transitionLeave={false}` props to `ReactCSSTransitionGroup` to disable these animations.

0 commit comments

Comments
 (0)