Skip to content

Commit

Permalink
Editor auto-position now respects iframe bounds (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimon committed Sep 3, 2022
1 parent b92bd8d commit 745f04b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/editor/setPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,19 @@ const setPosition = (wrapperEl, editorEl, selectedEl, autoPosition) => {
if (autoPosition) {
const defaultOrientation = editorEl.children[1].getBoundingClientRect();

const { innerWidth, innerHeight } = wrapperEl.ownerDocument.defaultView;

// Test 1: does right edge extend beyond the width of the page?
// If so, flip horizontally
if (defaultOrientation.right > window.innerWidth) {
if (defaultOrientation.right > innerWidth) {
editorEl.classList.remove('r6o-arrow-left');
editorEl.classList.add('r6o-arrow-right');
editorEl.style.left = `${right - defaultOrientation.width - containerBounds.left}px`;
}

// Test 2: does the bottom edge extend beyond the height of the page?
// If so, flip vertically
if (defaultOrientation.bottom > window.innerHeight) {
if (defaultOrientation.bottom > innerHeight) {
editorEl.classList.remove('r6o-arrow-top');
editorEl.classList.add('r6o-arrow-bottom');

Expand Down

0 comments on commit 745f04b

Please sign in to comment.