Skip to content

Commit 131669b

Browse files
committed
[fixed] ModalTrigger passes onMouseOver prop and onMouseOut prop to child
1 parent 1249eff commit 131669b

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

src/ModalTrigger.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,13 @@ const ModalTrigger = React.createClass({
4949

5050
render() {
5151
let child = React.Children.only(this.props.children);
52-
return cloneElement(
53-
child,
54-
{
55-
onClick: createChainedFunction(child.props.onClick, this.toggle)
56-
}
57-
);
52+
let props = {};
53+
54+
props.onClick = createChainedFunction(child.props.onClick, this.toggle);
55+
props.onMouseOver = createChainedFunction(child.props.onMouseOver, this.props.onMouseOver);
56+
props.onMouseOut = createChainedFunction(child.props.onMouseOut, this.props.onMouseOut);
57+
58+
return cloneElement(child, props);
5859
}
5960
});
6061

test/ModalTriggerSpec.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import React from 'react';
2+
import ReactTestUtils from 'react/lib/ReactTestUtils';
3+
import ModalTrigger from '../src/ModalTrigger';
4+
5+
describe('ModalTrigger', function() {
6+
it('Should create ModalTrigger element', function() {
7+
let instance = ReactTestUtils.renderIntoDocument(
8+
<ModalTrigger modal={<div>test</div>}>
9+
<button>button</button>
10+
</ModalTrigger>
11+
);
12+
let modalTrigger = instance.getDOMNode();
13+
assert.equal(modalTrigger.nodeName, 'BUTTON');
14+
});
15+
16+
it('Should pass ModalTrigger onMouseOver prop to children', function() {
17+
let called = false;
18+
let callback = function() {
19+
called = true;
20+
};
21+
let instance = ReactTestUtils.renderIntoDocument(
22+
<ModalTrigger modal={<div>test</div>} onMouseOver={callback}>
23+
<button>button</button>
24+
</ModalTrigger>
25+
);
26+
let modalTrigger = instance.getDOMNode();
27+
ReactTestUtils.Simulate.mouseOver(modalTrigger);
28+
assert.equal(called, true);
29+
});
30+
31+
it('Should pass ModalTrigger onMouseOut prop to children', function() {
32+
let called = false;
33+
let callback = function() {
34+
called = true;
35+
};
36+
let instance = ReactTestUtils.renderIntoDocument(
37+
<ModalTrigger modal={<div>test</div>} onMouseOut={callback}>
38+
<button>button</button>
39+
</ModalTrigger>
40+
);
41+
let modalTrigger = instance.getDOMNode();
42+
ReactTestUtils.Simulate.mouseOut(modalTrigger);
43+
assert.equal(called, true);
44+
});
45+
});

0 commit comments

Comments
 (0)