Skip to content

Commit

Permalink
Fix Transition passes through all props to children in production build
Browse files Browse the repository at this point in the history
  • Loading branch information
koba04 committed Jul 21, 2017
1 parent 20b16c6 commit 226213f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Transition.js
Expand Up @@ -303,7 +303,21 @@ class Transition extends React.Component {
}

const {children, ...childProps} = this.props;
Object.keys(Transition.propTypes).forEach(key => delete childProps[key]);
// filter props for Transtition
delete childProps.in;
delete childProps.mountOnEnter;
delete childProps.unmountOnExit;
delete childProps.appear;
delete childProps.enter;
delete childProps.exit;
delete childProps.timeout;
delete childProps.addEndListener;
delete childProps.onEnter;
delete childProps.onEntering;
delete childProps.onEntered;
delete childProps.onExit;
delete childProps.onExiting;
delete childProps.onExited;

if (typeof children === 'function') {
return children(status, childProps)
Expand All @@ -313,7 +327,6 @@ class Transition extends React.Component {
return React.cloneElement(child, childProps);
}
}

Transition.propTypes = {
/**
* A `function` child can be used instead of a React element.
Expand Down Expand Up @@ -449,6 +462,7 @@ Transition.propTypes = {
onExited: PropTypes.func,
};


// Name the function so it is clearer in the documentation
function noop() {}

Expand Down
34 changes: 34 additions & 0 deletions test/Transition-test.js
Expand Up @@ -55,6 +55,40 @@ describe('Transition', () => {
.render();
});

it('should pass filtered props to children', () => {
class Child extends React.Component {
render() {
return <div>child</div>;
}
}
const child = tsp(
<Transition
foo="foo"
bar="bar"
in
mountOnEnter
unmountOnExit
appear
enter
exit
timeout={0}
addEndListener={() => {}}
onEnter={() => {}}
onEntering={() => {}}
onEntered={() => {}}
onExit={() => {}}
onExiting={() => {}}
onExited={() => {}}
>
<Child />
</Transition>
)
.render()
.find(Child);

expect(child.props()).toEqual({foo: 'foo', bar: 'bar'});
});

describe('entering', () => {
let instance;

Expand Down

0 comments on commit 226213f

Please sign in to comment.