Close context menu on resize

This commit is contained in:
Thomas Weber committed 2021-07-02 00:20:16 -05:00
1 parent d9b6d2cd85
commit 00d4ed48a5
1 file changed
+8 -1
+8 -1
View File
@@ -7,7 +7,8 @@ class ContextMenu {
this.root = document.createElement('div');
this.root.className = styles.contextMenu;
this._onmousedown = this._onmousedown.bind(this)
this._onmousedown = this._onmousedown.bind(this);
this._onresize = this._onresize.bind(this);
}
_onmousedown (e) {
@@ -16,6 +17,10 @@ class ContextMenu {
}
}
_onresize () {
this.destroy();
}
add (option) {
const item = document.createElement('button');
item.className = styles.contextMenuItem;
@@ -32,6 +37,7 @@ class ContextMenu {
show (mouseEvent) {
document.addEventListener('mousedown', this._onmousedown);
window.addEventListener('resize', this._onresize);
const layersRect = this.parent.layersRect;
const x = mouseEvent.clientX - layersRect.left + 1;
const y = mouseEvent.clientY - layersRect.top + 1;
@@ -41,6 +47,7 @@ class ContextMenu {
destroy () {
document.removeEventListener('mousedown', this._onmousedown);
window.removeEventListener('resize', this._onresize);
this.root.remove();
}
}