Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 0b19963

Browse files
committed
Fix CSSTransitionGroupChild wrong key
1 parent cca5e4b commit 0b19963

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/csstransitiongroup.spec.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ describe("csstransitiongroup.tsx", () => {
5858
wrapper.setProps({ children: [<span />] });
5959
assert.isTrue((wrapper.find("CSSTransitionGroupChild").props() as any).mounted);
6060
});
61+
62+
it("should set key of CSSTransitionGroupChild to match keys of children", () => {
63+
const wrapper = getWrapper(
64+
{ id: "abc", children: [<span key="mykey" />] },
65+
);
66+
assert.strictEqual((wrapper.find("CSSTransitionGroupChild").key()), ".$mykey");
67+
});
6168
});
6269

6370
describe("<CSSTransitionGroupChild>", () => {

src/csstransitiongroup.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ export class CSSTransitionGroup extends Component<CSSTransitionGroupProps, {}> {
2525
const { transitionAppear, children, ...rest } = this.props as any;
2626
return (
2727
<ReactTransitionGroup {...rest}>
28-
{Children.map(children, (child, index) =>
28+
{Children.map(children, (child: ReactElement<any>, index) =>
2929
<CSSTransitionGroupChild
3030
transitionAppear={transitionAppear}
3131
mounted={this.mounted}
32-
key={index}>
32+
key={child.key}>
3333
{child}
3434
</CSSTransitionGroupChild>,
3535
)}

0 commit comments

Comments
 (0)