Skip to content
This repository was archived by the owner on Sep 1, 2020. It is now read-only.

Commit 9ae47c9

Browse files
committed
add some checks
1 parent 098d0dc commit 9ae47c9

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/ContextMenu.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,15 @@ export default class ContextMenu extends AbstractMenu {
5858
const { top, left } = this.getMenuPosition(x, y);
5959

6060
wrapper(() => {
61+
if (!this.menu) return;
6162
this.menu.style.top = `${top}px`;
6263
this.menu.style.left = `${left}px`;
6364
this.menu.style.opacity = 1;
6465
this.menu.style.pointerEvents = 'auto';
6566
});
6667
});
6768
} else {
69+
if (!this.menu) return;
6870
this.menu.style.opacity = 0;
6971
this.menu.style.pointerEvents = 'none';
7072
}
@@ -145,13 +147,16 @@ export default class ContextMenu extends AbstractMenu {
145147
}
146148

147149
getMenuPosition = (x = 0, y = 0) => {
148-
const { innerWidth, innerHeight } = window;
149-
const rect = this.menu.getBoundingClientRect();
150-
const menuStyles = {
150+
let menuStyles = {
151151
top: y,
152152
left: x
153153
};
154154

155+
if (!this.menu) return menuStyles;
156+
157+
const { innerWidth, innerHeight } = window;
158+
const rect = this.menu.getBoundingClientRect();
159+
155160
if (y + rect.height > innerHeight) {
156161
menuStyles.top -= rect.height;
157162
}

0 commit comments

Comments
 (0)