Skip to content

Commit 4b618b6

Browse files
authored
Merge pull request #8279 from imadx/im-branch-2
Fix issue with context menu behaviour when extending beyond the boundaries of the window
2 parents 355db8a + 43d4a4a commit 4b618b6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/ui/src/lib/ContextMenu.svelte

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@
101101
102102
function setAlignByMouse(e?: MouseEvent) {
103103
if (!e) return;
104-
menuPosition = { x: e.clientX, y: e.clientY };
104+
const clientX = horizontalAlign === 'left' ? e.clientX - contextMenuWidth : e.clientX;
105+
const clientY = side === 'top' ? e.clientY - contextMenuHeight : e.clientY;
106+
107+
menuPosition = { x: clientX, y: clientY };
105108
}
106109
107110
function setAlignByTarget(target: HTMLElement) {
@@ -170,9 +173,11 @@
170173
horizontalAlign = 'left';
171174
setAlignment();
172175
}
173-
if (rect.bottom > viewport.bottom) {
174-
side = 'top';
175-
setAlignment();
176+
if (rect.bottom > viewport.bottom && rect.top > viewport.top) {
177+
setTimeout(() => {
178+
side = 'top';
179+
setAlignment();
180+
}, 0);
176181
}
177182
if (rect.top < viewport.top) {
178183
side = 'bottom';

0 commit comments

Comments
 (0)