From 3fee68b692ab4a175f62acb55e76b563473f5192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20Ku=CC=88hn?= Date: Fri, 19 Jul 2019 23:46:44 +0200 Subject: [PATCH] prevent error in bubble menu, fix #386 --- packages/tiptap/src/Plugins/FloatingMenu.js | 9 ++++++++- packages/tiptap/src/Plugins/MenuBubble.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/tiptap/src/Plugins/FloatingMenu.js b/packages/tiptap/src/Plugins/FloatingMenu.js index 2441b1d64..de3a04ed1 100644 --- a/packages/tiptap/src/Plugins/FloatingMenu.js +++ b/packages/tiptap/src/Plugins/FloatingMenu.js @@ -66,7 +66,14 @@ class Menu { return } - const editorBoundings = this.options.element.offsetParent.getBoundingClientRect() + const parent = this.options.element.offsetParent + + if (!parent) { + this.hide() + return + } + + const editorBoundings = parent.getBoundingClientRect() const cursorBoundings = view.coordsAtPos(state.selection.anchor) const top = cursorBoundings.top - editorBoundings.top diff --git a/packages/tiptap/src/Plugins/MenuBubble.js b/packages/tiptap/src/Plugins/MenuBubble.js index 2a43992bd..1e2f9e707 100644 --- a/packages/tiptap/src/Plugins/MenuBubble.js +++ b/packages/tiptap/src/Plugins/MenuBubble.js @@ -111,7 +111,14 @@ class Menu { const end = coordsAtPos(view, to, true) // The box in which the tooltip is positioned, to use as base - const box = this.options.element.offsetParent.getBoundingClientRect() + const parent = this.options.element.offsetParent + + if (!parent) { + this.hide() + return + } + + const box = parent.getBoundingClientRect() const el = this.options.element.getBoundingClientRect() // Find a center-ish x position from the selection endpoints (when