Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add offset to limitShift functionality to compensate iframe s offset
  • Loading branch information
ciampo committed Sep 22, 2022
commit cf718899a7243b72c48bcb8cfbaa49b649388c03
37 changes: 36 additions & 1 deletion packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,42 @@ const UnforwardedPopover = (
shouldShift
? shiftMiddleware( {
crossAxis: true,
limiter: limitShift(),
limiter: limitShift( {
offset: ( { placement: currentPlacement } ) => {
// The following calculations are aimed at allowing the floating
// element to shift fully below the reference element, when the
// reference element is in a different document (i.e. an iFrame).
if (
referenceOwnerDocument === document ||
frameOffsetRef.current === undefined
) {
return 0;
}

// The main axis (according to floating UI's docs) is the "x" axis
// for 'top' and 'bottom' placements, and the "y" axis for 'left'
// and 'right' placements.
const mainAxis = isTopBottomPlacement(
currentPlacement
)
? 'x'
: 'y';
const crossAxis = mainAxis === 'x' ? 'y' : 'x';

const crossAxisModifier = hasBeforePlacement(
currentPlacement
)
? -1
: 1;

return {
mainAxis: -frameOffsetRef.current[ mainAxis ],
crossAxis:
crossAxisModifier *
frameOffsetRef.current[ crossAxis ],
};
},
} ),
padding: 1, // Necessary to avoid flickering at the edge of the viewport.
} )
: undefined,
Expand Down