Skip to content

Commit

Permalink
fix: offsetParent being null type error
Browse files Browse the repository at this point in the history
  • Loading branch information
luwes committed Sep 26, 2024
1 parent cc4b980 commit 3281fd6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/js/utils/anchor-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function getRectRelativeToOffsetParent(
offsetParent: Element
): Rect {
const rect = element.getBoundingClientRect();
const offsetRect = offsetParent.getBoundingClientRect();
// offsetParent returns null in the following situations:
// - The element or any ancestor has the display property set to none.
// - The element has the position property set to fixed (Firefox returns <body>).
// - The element is <body> or <html>.
const offsetRect = offsetParent?.getBoundingClientRect() ?? { x: 0, y: 0 };
return {
x: rect.x - offsetRect.x,
y: rect.y - offsetRect.y,
Expand Down

0 comments on commit 3281fd6

Please sign in to comment.