From c7ac40590d88c31497071f14cd784861573c5983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Dobe=C5=A1?= Date: Fri, 18 Sep 2015 14:24:16 +0200 Subject: [PATCH] feat: onClick doesn't override main click handler [close #4] --- modules/link-factory.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/link-factory.js b/modules/link-factory.js index 8a5fdc7..bc0f539 100644 --- a/modules/link-factory.js +++ b/modules/link-factory.js @@ -40,6 +40,14 @@ function linkFactory(router) { }, clickHandler(evt) { + if (this.props.onClick) { + this.props.onClick(evt); + + if (evt.defaultPrevented) { + return; + } + } + let comboKey = event.metaKey || event.altKey || event.ctrlKey || event.shiftKey; if (evt.button === 0 && !comboKey) { @@ -70,7 +78,7 @@ function linkFactory(router) { let href = router.buildUrl(props.routeName, props.routeParams) let className = (props.className ? props.className.split(' ') : []) .concat(active ? [props.activeClassName] : []).join(' ') - let onClick = props.onClick || this.clickHandler + let onClick = this.clickHandler return React.createElement('a', {href, className, onClick}, props.children) }