commit 0f52e728f87a1df4765749feb056235b1616ebbf
parent b86f3910f29beca806a1cee14033891d8e2a1cf8
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Tue, 7 Feb 2017 00:05:06 +0300
[contextmenu] run callback on mouse click instead of mousedown events to avoid clicks not working when modal dialog shows in Chrome
Diffstat:
1 file changed, 21 insertions(+), 4 deletions(-)
diff --git a/src/lib/contextmenu/index.js b/src/lib/contextmenu/index.js
@@ -8,6 +8,20 @@ import './contextmenu.css';
{text: 'section', separator: true},
]
*/
+
+function isDescendant(parent, child) {
+ if (!parent) {
+ return false;
+ }
+ while (child) {
+ if (child === parent) {
+ return true;
+ }
+ child = child.parentNode;
+ }
+}
+
+
class Contextmenu {
constructor(items) {
this.items = items;
@@ -59,8 +73,10 @@ class Contextmenu {
}
};
- onMouseDown = () => {
- this.hide();
+ onMouseDown = (e) => {
+ if (!isDescendant(this._container, e.target)) {
+ this.hide();
+ }
};
setPosition(x, y) {
@@ -106,15 +122,16 @@ class Contextmenu {
const callback = itemOptions.callback;
if (callback && !itemOptions.disabled) {
- el.addEventListener('mousedown', this.onItemClick.bind(this, callback));
+ el.addEventListener('click', this.onItemClick.bind(this, callback));
}
return el;
}
onItemClick(callback, e) {
- callback(e);
e.stopPropagation();
e.preventDefault();
+ this.hide();
+ setTimeout(() => callback(e), 0);
}
createSeparator(itemOptions) {