Skip to content

Commit

Permalink
Merge pull request #4 from khankuan/feature/pass-props
Browse files Browse the repository at this point in the history
Allow TransitionChild to passprops. Useful for component wrapper that…
  • Loading branch information
jquense committed Jan 20, 2017
2 parents c9064f6 + b26fc0b commit 06cf519
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -50,6 +50,7 @@
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-dev-expression": "^0.2.1",
"babel-preset-latest": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-2": "^6.18.0",
"eslint": "^3.10.2",
"eslint-config-airbnb": "^13.0.0",
Expand Down
10 changes: 9 additions & 1 deletion src/CSSTransitionGroupChild.js
Expand Up @@ -157,7 +157,15 @@ class CSSTransitionGroupChild extends React.Component {
}

render() {
return React.Children.only(this.props.children);
const props = { ...this.props };
delete props.name;
delete props.appear;
delete props.enter;
delete props.leave;
delete props.appearTimeout;
delete props.enterTimeout;
delete props.leaveTimeout;
return React.cloneElement(React.Children.only(this.props.children), props);
}
}

Expand Down
42 changes: 42 additions & 0 deletions test/CSSTransitionGroup-test.js
Expand Up @@ -319,4 +319,46 @@ describe('CSSTransitionGroup', () => {
// Testing that no exception is thrown here, as the timeout has been cleared.
jest.runAllTimers();
});

it('should work with custom component wrapper cloning children', () => {
const extraClassNameProp = 'wrapper-item';
class Wrapper extends React.Component {
render() {
return (
<div>
{
React.Children.map(this.props.children,
child => React.cloneElement(child, { className: extraClassNameProp }))
}
</div>
);
}
}

class Child extends React.Component {
render() {
return <div {...this.props} />;
}
}

class Component extends React.Component {
render() {
return (
<CSSTransitionGroup
transitionName="yolo"
component={Wrapper}
>
<Child />
</CSSTransitionGroup>
);
}
}

const a = ReactDOM.render(<Component />, container);
const child = ReactDOM.findDOMNode(a).childNodes[0];
expect(hasClass(child, extraClassNameProp)).toBe(true);

// Testing that no exception is thrown here, as the timeout has been cleared.
jest.runAllTimers();
});
});

0 comments on commit 06cf519

Please sign in to comment.