Fixing list context menu being killed

This commit is contained in:
James Barnsley
2017-11-18 09:01:43 +13:00
parent db3d364939
commit b837f53767
2 changed files with 16 additions and 6 deletions

View File

@ -22,17 +22,17 @@ class ContextMenu extends React.Component{
submenu_expanded: false
}
this.handleScroll = this.handleScroll.bind(this)
this.handleClick = this.handleClick.bind(this)
this.handleMouseDown = this.handleMouseDown.bind(this)
}
componentDidMount(){
window.addEventListener("scroll", this.handleScroll, false)
window.addEventListener("click", this.handleClick, false)
window.addEventListener("mousedown", this.handleMouseDown, false)
}
componentWillUnmount(){
window.removeEventListener("scroll", this.handleScroll, false)
window.removeEventListener("click", this.handleClick, false)
window.removeEventListener("mousedown", this.handleMouseDown, false)
}
componentWillReceiveProps(nextProps){
@ -74,7 +74,7 @@ class ContextMenu extends React.Component{
}
}
handleClick(e){
handleMouseDown(e){
// if we click outside of the context menu or context menu trigger, kill it
if ($(e.target).closest('.context-menu').length <= 0 && $(e.target).closest('.context-menu-trigger').length <= 0){
this.props.uiActions.hideContextMenu()

View File

@ -8,6 +8,16 @@ export default class ContextMenuTrigger extends React.Component{
super(props);
}
handleMouseDown(e){
e.stopPropagation();
this.props.onTrigger(e);
}
handleTouchEnd(e){
e.stopPropagation();
this.props.onTrigger(e);
}
render(){
var className = 'context-menu-trigger'
if (this.props.className){
@ -15,8 +25,8 @@ export default class ContextMenuTrigger extends React.Component{
}
return (
<span className={className}
onMouseDown={e => this.props.onTrigger(e)}
onTouchEnd={e => this.props.onTrigger(e)}>
onMouseDown={e => this.handleMouseDown(e)}
onTouchEnd={e => this.handleTouchEnd(e)}>
<span className="dot"></span>
<span className="dot"></span>
<span className="dot"></span>