check if to far left before right

This commit is contained in:
Bernt Christian Egeland 2021-12-12 00:59:39 +01:00
parent 4e3f07f337
commit 3b7b3e3064

View File

@ -69,14 +69,15 @@ export default function RelativeModal({
let newTop = top; let newTop = top;
let newLeft = left; let newLeft = left;
// too far right
if (newLeft + width + WINDOW_PADDING >= windowWidth - WINDOW_PADDING) {
newLeft = windowWidth - width - WINDOW_PADDING;
}
// too far left // too far left
else if (left < WINDOW_PADDING) { if (left < WINDOW_PADDING) {
newLeft = WINDOW_PADDING; newLeft = WINDOW_PADDING;
} }
// too far right
else if (newLeft + width + WINDOW_PADDING >= windowWidth - WINDOW_PADDING) {
newLeft = windowWidth - width - WINDOW_PADDING;
}
// too close to bottom // too close to bottom
if (top + menuHeight > windowHeight - WINDOW_PADDING + window.scrollY) { if (top + menuHeight > windowHeight - WINDOW_PADDING + window.scrollY) {
newTop = WINDOW_PADDING; newTop = WINDOW_PADDING;