From 131669b25a162805942716ce1a501f7b9bf8a1e7 Mon Sep 17 00:00:00 2001 From: Teloo Date: Sun, 26 Apr 2015 11:49:18 +0900 Subject: [PATCH] [fixed] ModalTrigger passes onMouseOver prop and onMouseOut prop to child --- src/ModalTrigger.js | 13 ++++++------ test/ModalTriggerSpec.js | 45 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 test/ModalTriggerSpec.js diff --git a/src/ModalTrigger.js b/src/ModalTrigger.js index 6afea34271..facb1414a1 100644 --- a/src/ModalTrigger.js +++ b/src/ModalTrigger.js @@ -49,12 +49,13 @@ const ModalTrigger = React.createClass({ render() { let child = React.Children.only(this.props.children); - return cloneElement( - child, - { - onClick: createChainedFunction(child.props.onClick, this.toggle) - } - ); + let props = {}; + + props.onClick = createChainedFunction(child.props.onClick, this.toggle); + props.onMouseOver = createChainedFunction(child.props.onMouseOver, this.props.onMouseOver); + props.onMouseOut = createChainedFunction(child.props.onMouseOut, this.props.onMouseOut); + + return cloneElement(child, props); } }); diff --git a/test/ModalTriggerSpec.js b/test/ModalTriggerSpec.js new file mode 100644 index 0000000000..1f90db52fd --- /dev/null +++ b/test/ModalTriggerSpec.js @@ -0,0 +1,45 @@ +import React from 'react'; +import ReactTestUtils from 'react/lib/ReactTestUtils'; +import ModalTrigger from '../src/ModalTrigger'; + +describe('ModalTrigger', function() { + it('Should create ModalTrigger element', function() { + let instance = ReactTestUtils.renderIntoDocument( + test}> + + + ); + let modalTrigger = instance.getDOMNode(); + assert.equal(modalTrigger.nodeName, 'BUTTON'); + }); + + it('Should pass ModalTrigger onMouseOver prop to children', function() { + let called = false; + let callback = function() { + called = true; + }; + let instance = ReactTestUtils.renderIntoDocument( + test} onMouseOver={callback}> + + + ); + let modalTrigger = instance.getDOMNode(); + ReactTestUtils.Simulate.mouseOver(modalTrigger); + assert.equal(called, true); + }); + + it('Should pass ModalTrigger onMouseOut prop to children', function() { + let called = false; + let callback = function() { + called = true; + }; + let instance = ReactTestUtils.renderIntoDocument( + test} onMouseOut={callback}> + + + ); + let modalTrigger = instance.getDOMNode(); + ReactTestUtils.Simulate.mouseOut(modalTrigger); + assert.equal(called, true); + }); +});