mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2024-12-29 18:09:05 +01:00
make sure popup position is never off screen to the left
This commit is contained in:
parent
917e67d356
commit
101ca9e0f7
1 changed files with 10 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue