From 81ec6729c86cdcc042f5bff4d5816aee7ff4acfe Mon Sep 17 00:00:00 2001 From: Kevin Ansfield Date: Fri, 6 Nov 2020 18:13:32 +0000 Subject: [PATCH] Fixed error when creating a block-editable card in the editor no issue The toolbar display/positioning logic was recently changed so that the toolbar is shown when a `saveAsSnippet` action is passed in. However the `_setToolbarProperties` method wasn't taking into account the toolbar element not being present when in editing mode such as when a block-editable card (markdown, html, code) is created. - remove conditional logic that may change over time and replace it with checks for the toolbar element existing --- .../addon/components/koenig-card.js | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js b/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js index b8aae82dbb..10b075b87d 100644 --- a/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js +++ b/ghost/admin/lib/koenig-editor/addon/components/koenig-card.js @@ -249,17 +249,20 @@ export default Component.extend({ }, _setToolbarProperties() { - if (this.toolbar || this.saveAsSnippet) { - // select the last toolbar in the element because card contents/captions - // may have their own toolbar elements - let toolbar = this.element.querySelector(':scope > [data-kg-toolbar="true"]'); - let {width, height} = toolbar.getBoundingClientRect(); + // select the last toolbar in the element because card contents/captions + // may have their own toolbar elements + let toolbar = this.element?.querySelector(':scope > [data-kg-toolbar="true"]'); - this.setProperties({ - toolbarWidth: width, - toolbarHeight: height + TICK_HEIGHT - }); + if (!toolbar) { + return; } + + let {width, height} = toolbar.getBoundingClientRect(); + + this.setProperties({ + toolbarWidth: width, + toolbarHeight: height + TICK_HEIGHT + }); }, _showToolbar() {