Skip to content

Commit

Permalink
Change unaligned behavior to keep top and left edges visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Macil committed Sep 29, 2023
1 parent 0a058aa commit 5c62704
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,16 @@ function positionAndAlign(
left = Math.ceil(anchorRect.right - elRect.width);
break;
case "unaligned": {
left = Math.max(
buffers.all + buffers.left,
Math.round((anchorRect.left + anchorRect.right - elRect.width) / 2),
left = Math.round(
(anchorRect.left + anchorRect.right - elRect.width) / 2,
);
const overhang = Math.ceil(
left + elRect.width + buffers.all + buffers.right - window.innerWidth,
);
if (overhang > 0) {
left -= overhang;
}
left = Math.max(buffers.all + buffers.left, left);
break;
}
default:
Expand All @@ -290,9 +290,8 @@ function positionAndAlign(
top = Math.ceil(anchorRect.bottom - elRect.height);
break;
case "unaligned": {
top = Math.max(
buffers.all + buffers.top,
Math.round((anchorRect.top + anchorRect.bottom - elRect.height) / 2),
top = Math.round(
(anchorRect.top + anchorRect.bottom - elRect.height) / 2,
);
const overhang = Math.ceil(
top +
Expand All @@ -304,6 +303,7 @@ function positionAndAlign(
if (overhang > 0) {
top -= overhang;
}
top = Math.max(buffers.all + buffers.top, top);
break;
}
default:
Expand Down Expand Up @@ -337,16 +337,16 @@ function positionAndAlign(
left = Math.round(anchorRect.right - elRect.width);
break;
case "unaligned": {
left = Math.max(
buffers.all + buffers.left,
Math.round((anchorRect.left + anchorRect.right - elRect.width) / 2),
left = Math.round(
(anchorRect.left + anchorRect.right - elRect.width) / 2,
);
const overhang = Math.ceil(
left + elRect.width + buffers.all + buffers.right - window.innerWidth,
);
if (overhang > 0) {
left -= overhang;
}
left = Math.max(buffers.all + buffers.left, left);
break;
}
default:
Expand Down Expand Up @@ -380,9 +380,8 @@ function positionAndAlign(
top = Math.round(anchorRect.bottom - elRect.height);
break;
case "unaligned": {
top = Math.max(
buffers.all + buffers.top,
Math.round((anchorRect.top + anchorRect.bottom - elRect.height) / 2),
top = Math.round(
(anchorRect.top + anchorRect.bottom - elRect.height) / 2,
);
const overhang = Math.ceil(
top +
Expand All @@ -394,6 +393,7 @@ function positionAndAlign(
if (overhang > 0) {
top -= overhang;
}
top = Math.max(buffers.all + buffers.top, top);
break;
}
default:
Expand Down

0 comments on commit 5c62704

Please sign in to comment.