diff --git a/src/OverlayTrigger.js b/src/OverlayTrigger.js index 987a5d4c58..88e01b280b 100644 --- a/src/OverlayTrigger.js +++ b/src/OverlayTrigger.js @@ -90,14 +90,16 @@ const OverlayTrigger = React.createClass({ }, render() { + let child = React.Children.only(this.props.children); if (this.props.trigger === 'manual') { - return React.Children.only(this.props.children); + return child; } let props = {}; + props.onClick = createChainedFunction(child.props.onClick, this.props.onClick); if (isOneOf('click', this.props.trigger)) { - props.onClick = createChainedFunction(this.toggle, this.props.onClick); + props.onClick = createChainedFunction(this.toggle, props.onClick); } if (isOneOf('hover', this.props.trigger)) { @@ -111,7 +113,7 @@ const OverlayTrigger = React.createClass({ } return cloneElement( - React.Children.only(this.props.children), + child, props ); }, diff --git a/test/OverlayTriggerSpec.js b/test/OverlayTriggerSpec.js new file mode 100644 index 0000000000..e2e358216a --- /dev/null +++ b/test/OverlayTriggerSpec.js @@ -0,0 +1,30 @@ +import React from 'react'; +import ReactTestUtils from 'react/lib/ReactTestUtils'; +import OverlayTrigger from '../src/OverlayTrigger'; + +describe('OverlayTrigger', function() { + it('Should create OverlayTrigger element', function() { + let instance = ReactTestUtils.renderIntoDocument( + test}> + + + ); + let overlayTrigger = instance.getDOMNode(); + assert.equal(overlayTrigger.nodeName, 'BUTTON'); + }); + + it('Should pass OverlayTrigger onClick prop to child', function() { + let called = false; + let callback = function() { + called = true; + }; + let instance = ReactTestUtils.renderIntoDocument( + test} onClick={callback}> + + + ); + let overlayTrigger = instance.getDOMNode(); + ReactTestUtils.Simulate.click(overlayTrigger); + assert.equal(called, true); + }); +});