Skip to content

Commit

Permalink
Move fix to getBoundingClientRect
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Sep 14, 2022
1 parent 5c6d8dd commit f3fe19b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
23 changes: 17 additions & 6 deletions packages/dom/src/utils/getBoundingClientRect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,25 @@ export function getBoundingClientRect(
const win = isElement(element) ? getWindow(element) : window;
const addVisualOffsets = !isLayoutViewport() && isFixedStrategy;

const ownerDocOffset = {x: 0, y: 0};
if (win.frameElement) {
const iFrameBCR = win.frameElement.getBoundingClientRect();
ownerDocOffset.x = iFrameBCR.left;
ownerDocOffset.y = iFrameBCR.top;
}

const x =
(clientRect.left +
(addVisualOffsets ? win.visualViewport?.offsetLeft ?? 0 : 0)) /
scaleX;
(
clientRect.left +
(addVisualOffsets ? win.visualViewport?.offsetLeft ?? 0 : 0) +
ownerDocOffset.x
) / scaleX;
const y =
(clientRect.top +
(addVisualOffsets ? win.visualViewport?.offsetTop ?? 0 : 0)) /
scaleY;
(
clientRect.top +
(addVisualOffsets ? win.visualViewport?.offsetTop ?? 0 : 0) +
ownerDocOffset.y
) / scaleY;
const width = clientRect.width / scaleX;
const height = clientRect.height / scaleY;

Expand Down
14 changes: 2 additions & 12 deletions packages/dom/src/utils/getRectRelativeToOffsetParent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,9 @@ export function getRectRelativeToOffsetParent(
}
}

const ownerDocOffset = {x: 0, y: 0};

// TODO: improve checks
if (element?.ownerDocument?.defaultView?.frameElement) {
const bcr =
element.ownerDocument.defaultView.frameElement.getBoundingClientRect();
ownerDocOffset.x = bcr.left;
ownerDocOffset.y = bcr.top;
}

return {
x: rect.left + scroll.scrollLeft - offsets.x + ownerDocOffset.x,
y: rect.top + scroll.scrollTop - offsets.y + ownerDocOffset.y,
x: rect.left + scroll.scrollLeft - offsets.x,
y: rect.top + scroll.scrollTop - offsets.y,
width: rect.width,
height: rect.height,
};
Expand Down

0 comments on commit f3fe19b

Please sign in to comment.