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:
parent
70d390ea2e
commit
b70b2a859d
2 changed files with 4 additions and 5 deletions
|
@ -15,9 +15,9 @@ export let Link = React.createClass({
|
||||||
disabled: false,
|
disabled: false,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
handleClick: function() {
|
handleClick: function(e) {
|
||||||
if (this.props.onClick) {
|
if (this.props.onClick) {
|
||||||
this.props.onClick();
|
this.props.onClick(e);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
|
|
|
@ -42,21 +42,20 @@ export let DropDownMenu = React.createClass({
|
||||||
window.removeEventListener('click', this.handleWindowClick, false);
|
window.removeEventListener('click', this.handleWindowClick, false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onMenuIconClick: function() {
|
onMenuIconClick: function(e) {
|
||||||
this.setState({
|
this.setState({
|
||||||
menuOpen: !this.state.menuOpen,
|
menuOpen: !this.state.menuOpen,
|
||||||
});
|
});
|
||||||
if (!this.state.menuOpen && !this._isWindowClickBound) {
|
if (!this.state.menuOpen && !this._isWindowClickBound) {
|
||||||
this._isWindowClickBound = true;
|
this._isWindowClickBound = true;
|
||||||
window.addEventListener('click', this.handleWindowClick, false);
|
window.addEventListener('click', this.handleWindowClick, false);
|
||||||
|
e.stopPropagation();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
handleWindowClick: function(e) {
|
handleWindowClick: function(e) {
|
||||||
if (this.state.menuOpen &&
|
if (this.state.menuOpen &&
|
||||||
(!this._menuDiv || !this._menuDiv.contains(e.target))) {
|
(!this._menuDiv || !this._menuDiv.contains(e.target))) {
|
||||||
console.log('menu closing disabled due to auto close on click, fix me');
|
|
||||||
return;
|
|
||||||
this.setState({
|
this.setState({
|
||||||
menuOpen: false
|
menuOpen: false
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue