From 580ece0352f313bf26385dd714bd98e75a75ac7b Mon Sep 17 00:00:00 2001 From: Rainer Simon Date: Wed, 8 Apr 2020 09:10:37 +0200 Subject: [PATCH] Cleanup + editor positioning fix --- src/TextAnnotator.jsx | 2 +- src/editor/Editor.jsx | 2 +- src/editor/setPosition.js | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/TextAnnotator.jsx b/src/TextAnnotator.jsx index aa79f26..dad481e 100644 --- a/src/TextAnnotator.jsx +++ b/src/TextAnnotator.jsx @@ -182,7 +182,7 @@ export default class TextAnnotator extends Component { { setCurrentAnnotation(props.annotation); if (element.current) - setPosition(props.containerEl, element.current, props.bounds); + setPosition(props.wrapperEl, element.current, props.bounds); }, [ props.annotation ]); const onAppendBody = body => setCurrentAnnotation( diff --git a/src/editor/setPosition.js b/src/editor/setPosition.js index 73cf5f9..965fe1c 100644 --- a/src/editor/setPosition.js +++ b/src/editor/setPosition.js @@ -1,7 +1,7 @@ /** Sets the editor position and determines a proper orientation **/ -const setPosition = (containerEl, editorEl, annotationBounds) => { +const setPosition = (wrapperEl, editorEl, annotationBounds) => { // Container element offset - const { offsetLeft, offsetTop } = containerEl; + const { offsetLeft, offsetTop } = wrapperEl; const { scrollX, scrollY } = window; // Re-set orientation class @@ -20,10 +20,10 @@ const setPosition = (containerEl, editorEl, annotationBounds) => { editorEl.style.left = `${right - defaultOrientation.width + scrollX - offsetLeft}px`; } - if (defaultOrientation.bottom > window.innerHeight) { + if (defaultOrientation.bottom > window.innerHeight - scrollY) { // Flip vertically const annotationTop = top + scrollY; // Annotation top relative to parents - const containerBounds = containerEl.getBoundingClientRect(); + const containerBounds = wrapperEl.getBoundingClientRect(); const containerHeight = containerBounds.height + containerBounds.top + scrollY; editorEl.classList.add('align-bottom');