Fix handling of window click events in DropDownMenu

Wasn't doing e.stopPropagation() when mounting the handler for clicks
outside the menu.
This commit is contained in:
Alex Liebowitz 2017-01-13 10:44:23 -05:00
parent 70d390ea2e
commit b70b2a859d
2 changed files with 4 additions and 5 deletions

View file

@ -15,9 +15,9 @@ export let Link = React.createClass({
disabled: false,
};
},
handleClick: function() {
handleClick: function(e) {
if (this.props.onClick) {
this.props.onClick();
this.props.onClick(e);
}
},
render: function() {

View file

@ -42,21 +42,20 @@ export let DropDownMenu = React.createClass({
window.removeEventListener('click', this.handleWindowClick, false);
}
},
onMenuIconClick: function() {
onMenuIconClick: function(e) {
this.setState({
menuOpen: !this.state.menuOpen,
});
if (!this.state.menuOpen && !this._isWindowClickBound) {
this._isWindowClickBound = true;
window.addEventListener('click', this.handleWindowClick, false);
e.stopPropagation();
}
return false;
},
handleWindowClick: function(e) {
if (this.state.menuOpen &&
(!this._menuDiv || !this._menuDiv.contains(e.target))) {
console.log('menu closing disabled due to auto close on click, fix me');
return;
this.setState({
menuOpen: false
});