Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TransitionChild to passprops. Useful for component wrapper that… #4

Merged
merged 2 commits into from Jan 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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();
});
});