Skip to content

Commit

Permalink
Use elementIsOutside helper
Browse files Browse the repository at this point in the history
  • Loading branch information
bregenspan committed Jan 29, 2019
1 parent 3b0eace commit 849e211
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion client/components/ContextMenu.jsx
Expand Up @@ -2,6 +2,7 @@
import {h, Component} from 'preact';
import cls from 'classnames';
import {store} from '../store';
import {elementIsOutside} from '../utils';

import s from './ContextMenu.css';

Expand Down Expand Up @@ -80,7 +81,7 @@ export default class ContextMenu extends Component {
}

handleDocumentMousedown = (e) => {
if (!this.node.contains(e.target)) {
if (elementIsOutside(e.target, this.node)) {
e.preventDefault();
e.stopPropagation();
this.hide();
Expand Down
4 changes: 4 additions & 0 deletions client/utils.js
Expand Up @@ -13,3 +13,7 @@ export function walkModules(modules, cb) {
}
}
}

export function elementIsOutside(elem, container) {
return !(elem === container || container.contains(elem));
}

0 comments on commit 849e211

Please sign in to comment.