Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix getOffset function to render elements in iframe offset from the p… #1934

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
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
22 changes: 16 additions & 6 deletions src/util/getOffset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export default function getOffset(
height: x.height,
};

let boundingFrameClientRect = {
top: 0,
left: 0
}

if((element) && (element.ownerDocument !== window.document))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add e2e tests for this?

{
boundingFrameClientRect = element.ownerDocument.defaultView.frameElement.getBoundingClientRect()
}

if (
(relativeEl.tagName.toLowerCase() !== "body" &&
relativeElPosition === "relative") ||
Expand All @@ -36,19 +46,19 @@ export default function getOffset(
// when the container of our target element is _not_ body and has either "relative" or "sticky" position, we should not
// consider the scroll position but we need to include the relative x/y of the container element
return Object.assign(obj, {
top: x.top - xr.top,
left: x.left - xr.left,
top: x.top - xr.top + boundingFrameClientRect.top,
left: x.left - xr.left + boundingFrameClientRect.left,
});
} else {
if (isFixed(element)) {
return Object.assign(obj, {
top: x.top,
left: x.left,
top: x.top + boundingFrameClientRect.top,
left: x.left + boundingFrameClientRect.left,
});
} else {
return Object.assign(obj, {
top: x.top + scrollTop,
left: x.left + scrollLeft,
top: x.top + scrollTop + boundingFrameClientRect.top,
left: x.left + scrollLeft + boundingFrameClientRect.left,
});
}
}
Expand Down