Skip to content

Commit

Permalink
use bottom sticky if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison-Stavlo committed Aug 19, 2021
1 parent 1308ed9 commit 03404b1
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/components/src/popover/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,11 @@ export function computePopoverYAxisPosition(

if ( stickyBoundaryElement ) {
const stickyRect = stickyBoundaryElement.getBoundingClientRect();
const stickyPosition = stickyRect.top + height - relativeOffsetTop;
const stickyPositionTop = stickyRect.top + height - relativeOffsetTop;
const stickyPositionBottom =
stickyRect.bottom - height - relativeOffsetTop;

if ( anchorRect.top <= stickyPosition ) {
if ( anchorRect.top <= stickyPositionTop ) {
if ( editorWrapper ) {
// If a popover cannot be positioned above the anchor, even after scrolling, we must
// ensure we use the bottom position instead of the popover slot. This prevents the
Expand All @@ -200,20 +202,20 @@ export function computePopoverYAxisPosition(
const isRoomAboveInCanvas =
height + HEIGHT_OFFSET <
editorWrapper.scrollTop + anchorRect.top;
const isRoomBelowVisually =
anchorRect.bottom + height + relativeOffsetTop <=
stickyRect.bottom;
if ( ! isRoomAboveInCanvas && isRoomBelowVisually ) {
if ( ! isRoomAboveInCanvas ) {
return {
yAxis: 'bottom',
popoverTop: anchorRect.bottom,
popoverTop: Math.min(
anchorRect.bottom,
stickyPositionBottom
),
};
}
}
// Default sticky behavior.
return {
yAxis,
popoverTop: Math.min( anchorRect.bottom, stickyPosition ),
popoverTop: Math.min( anchorRect.bottom, stickyPositionTop ),
};
}
}
Expand Down

0 comments on commit 03404b1

Please sign in to comment.