Skip to content

Instantly share code, notes, and snippets.

@slorber
Last active August 29, 2015 14:13
Show Gist options
  • Save slorber/bb38b4d482818ccbfed7 to your computer and use it in GitHub Desktop.
Save slorber/bb38b4d482818ccbfed7 to your computer and use it in GitHub Desktop.
var WithStopPropagation = React.createClass({
propTypes: {
children: React.PropTypes.node.isRequired,
eventNames: React.PropTypes.arrayOf(React.PropTypes.string).isRequired
},
componentDidMount: function() {
this.props.eventNames.forEach(function(eventName) {
$(this.getDOMNode()).on(eventName,function(e) {
e.stopPropagation();
});
}.bind(this));
},
render: function() {
return React.Children.only(this.props.children);
}
});
<WithStopPropagation eventNames={["click"]}>
<li className="file-attachment">
<div className="closeIcon" onClick={this.props.onClickOnCloseIcon}><CloseIcon/></div>
<a className="url" target="_blank" href={url}>
<div className="infos"><span className="name">{name}</span></div>
<div className="preview"><AttachmentIcon/></div>
</a>
</li>
</WithStopPropagation>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment