Skip to content

Commit 2fdfda0

Browse files
committed
Merge pull request #120 from taion/child-onClick
Call onClick on child as well
2 parents f911799 + b1fbbab commit 2fdfda0

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/LinkContainer.js

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export default class LinkContainer extends React.Component {
1616
return;
1717
}
1818

19+
if (this.props.children.props.onClick) {
20+
this.props.children.props.onClick(event);
21+
}
22+
1923
Link.prototype.handleClick.call(this, event);
2024
}
2125

tests/LinkContainer.spec.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,15 @@ describe('LinkContainer', () => {
104104
expect(target).to.exist;
105105
});
106106

107-
it('should call a user defined click handler', () => {
107+
it('should call user defined click handlers', () => {
108108
const onClick = sinon.spy();
109+
const childOnClick = sinon.spy();
109110

110111
class LinkWrapper extends React.Component {
111112
render() {
112113
return (
113114
<LinkContainer to="/foo" onClick={onClick}>
114-
<Component>Foo</Component>
115+
<Component onClick={childOnClick}>Foo</Component>
115116
</LinkContainer>
116117
);
117118
}
@@ -128,7 +129,8 @@ describe('LinkContainer', () => {
128129
);
129130
ReactTestUtils.Simulate.click(ReactDOM.findDOMNode(component));
130131

131-
expect(onClick).to.have.been.called;
132+
expect(onClick).to.have.been.calledOnce;
133+
expect(childOnClick).to.have.been.calledOnce;
132134
});
133135
});
134136

0 commit comments

Comments
 (0)