summaryrefslogtreecommitdiff
path: root/packages/frontend/src/scripts
diff options
context:
space:
mode:
authortess <me@thvxl.se>2024-11-12 21:16:59 +0100
committertess <me@thvxl.se>2024-11-12 21:39:38 +0100
commit101ca9e0f7e746f2188eac93d597fc42087e3662 (patch)
treea1701022521d983ac69bec30fbeb56f03db19823 /packages/frontend/src/scripts
parentmerge: Styling of following feed. (!738) (diff)
downloadsharkey-101ca9e0f7e746f2188eac93d597fc42087e3662.tar.gz
sharkey-101ca9e0f7e746f2188eac93d597fc42087e3662.tar.bz2
sharkey-101ca9e0f7e746f2188eac93d597fc42087e3662.zip
make sure popup position is never off screen to the left
Diffstat (limited to 'packages/frontend/src/scripts')
-rw-r--r--packages/frontend/src/scripts/popup-position.ts10
1 files changed, 10 insertions, 0 deletions
diff --git a/packages/frontend/src/scripts/popup-position.ts b/packages/frontend/src/scripts/popup-position.ts
index 3dad41a8b3..80ad91c48f 100644
--- a/packages/frontend/src/scripts/popup-position.ts
+++ b/packages/frontend/src/scripts/popup-position.ts
@@ -15,6 +15,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
const contentWidth = el.offsetWidth;
const contentHeight = el.offsetHeight;
+ const LEFT_MARGIN = 4;
+
let rect: DOMRect;
if (props.anchorElement) {
@@ -39,6 +41,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
left = window.innerWidth - contentWidth + window.scrollX - 1;
}
+ left = Math.max(LEFT_MARGIN, left);
+
return [left, top];
};
@@ -60,6 +64,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
left = window.innerWidth - contentWidth + window.scrollX - 1;
}
+ left = Math.max(LEFT_MARGIN, left);
+
return [left, top];
};
@@ -75,6 +81,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
top = props.y;
}
+ left = Math.max(LEFT_MARGIN, left);
+
top -= (el.offsetHeight / 2);
if (top + contentHeight - window.scrollY > window.innerHeight) {
@@ -106,6 +114,8 @@ export function calcPopupPosition(el: HTMLElement, props: {
top -= (el.offsetHeight / 2);
}
+ left = Math.max(LEFT_MARGIN, left);
+
if (top + contentHeight - window.scrollY > window.innerHeight) {
top = window.innerHeight - contentHeight + window.scrollY - 1;
}