From 708e82ea4474a9dfdfb2d67bf62d7f1d042b1cb7 Mon Sep 17 00:00:00 2001 From: Toru Kobayashi Date: Fri, 21 Jul 2017 14:13:38 +0900 Subject: [PATCH] Fix Transition passes through all props to children in production build (#123) --- src/Transition.js | 16 +++++++++++++++- test/Transition-test.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Transition.js b/src/Transition.js index c6118abc..6affcec4 100644 --- a/src/Transition.js +++ b/src/Transition.js @@ -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) diff --git a/test/Transition-test.js b/test/Transition-test.js index 37c7957b..d0be7c18 100644 --- a/test/Transition-test.js +++ b/test/Transition-test.js @@ -55,6 +55,40 @@ describe('Transition', () => { .render(); }); + it('should pass filtered props to children', () => { + class Child extends React.Component { + render() { + return
child
; + } + } + const child = tsp( + {}} + onEnter={() => {}} + onEntering={() => {}} + onEntered={() => {}} + onExit={() => {}} + onExiting={() => {}} + onExited={() => {}} + > + + + ) + .render() + .find(Child); + + expect(child.props()).toEqual({foo: 'foo', bar: 'bar'}); + }); + describe('entering', () => { let instance;