diff --git a/packages/ketcher-macromolecules/src/helpers/calculatePreviewTop.ts b/packages/ketcher-macromolecules/src/helpers/calculatePreviewTop.ts index d1743a4052..3d8c75f736 100644 --- a/packages/ketcher-macromolecules/src/helpers/calculatePreviewTop.ts +++ b/packages/ketcher-macromolecules/src/helpers/calculatePreviewTop.ts @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. ***************************************************************************/ +import { EditorClassName } from 'ketcher-react'; import { preview } from '../constants'; export const calculateMonomerPreviewTop = createCalculatePreviewTopFunction( @@ -31,7 +32,7 @@ function createCalculatePreviewTopFunction( height: number, ): (target?: DOMRect) => string { return function calculatePreviewTop(target?: DOMRect): string { - if (!target) { + if (!target || !getEditorDOMRect()) { return ''; } @@ -39,3 +40,9 @@ function createCalculatePreviewTopFunction( return `${top}px`; }; } + +function getEditorDOMRect(): DOMRect | undefined { + return document + .getElementsByClassName(EditorClassName)[0] + ?.getBoundingClientRect(); +}