Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 3 deletions
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+
<ComponentonClick={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)

AltStyle によって変換されたページ (->オリジナル) /