Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
🐛 Take the visual viewport into account for Safari when positioning t…
Browse files Browse the repository at this point in the history
…he popover

Otherwise it can be positioned wrongly after zooming by pinching
  • Loading branch information
lowiebenoot committed Jan 8, 2024
1 parent 89fac5d commit d7e3063
Showing 1 changed file with 27 additions and 16 deletions.
43 changes: 27 additions & 16 deletions src/components/popover/positionCalculation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,22 +131,33 @@ const getPositionValues = ({
anchorPosition,
popoverDimensions,
inputOffsetCorrection,
}: DirectionPositionValues) =>
direction === DIRECTION_NORTH || direction === DIRECTION_SOUTH
? getVerticalDirectionPositionValues({
direction,
position,
anchorPosition,
popoverDimensions,
inputOffsetCorrection,
})
: getHorizontalDirectionPositionValues({
direction,
position,
anchorPosition,
popoverDimensions,
inputOffsetCorrection,
});
}: DirectionPositionValues) => {
const positionValues =
direction === DIRECTION_NORTH || direction === DIRECTION_SOUTH
? getVerticalDirectionPositionValues({
direction,
position,
anchorPosition,
popoverDimensions,
inputOffsetCorrection,
})
: getHorizontalDirectionPositionValues({
direction,
position,
anchorPosition,
popoverDimensions,
inputOffsetCorrection,
});

// For Safari we need to take the visual viewport into account
// https://github.com/floating-ui/floating-ui/pull/1099/files#r418947428
if (/^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
positionValues.left += window.visualViewport?.offsetLeft || 0;
positionValues.top += window.visualViewport?.offsetTop || 0;
}

return positionValues;
};

const isInViewport = (direction: Direction, anchorPosition: PositionValues, popoverDimensions: DimensionValues) => {
switch (direction) {
Expand Down

0 comments on commit d7e3063

Please sign in to comment.