Skip to content

Commit 36f4817

Browse files
committed
fix: more options box gets out of viewport with very long elements
1 parent d53e3df commit 36f4817

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,15 @@ function RemoteFunctions(config) {
713713

714714
const isOverlap = checkOverlap(elemBounds.width, tagName, id, classes);
715715

716-
// default position (right aligned with element)
717-
let leftPos = elemBounds.right - boxWidth + scrollLeft;
716+
const viewportWidth = window.innerWidth;
717+
const idealLeftPos = elemBounds.right - boxWidth + scrollLeft;
718+
const maxLeftPos = viewportWidth - boxWidth - 10 + scrollLeft;
719+
// 10px is just the padding, because we want some space
720+
const minLeftPos = 10 + scrollLeft;
721+
722+
// we'll use the position that keeps the box within viewport bounds
723+
let leftPos = Math.min(idealLeftPos, maxLeftPos);
724+
leftPos = Math.max(leftPos, minLeftPos);
718725
let topPos;
719726

720727
if (isOverlap) {

0 commit comments

Comments
 (0)