Skip to content

Commit

Permalink
fix: getClientRectangle method fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Bayheck committed Aug 27, 2024
1 parent 4b81b8b commit c46f75d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/client/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,5 +900,11 @@ export function getAssociatedElement (el: HTMLElement): HTMLElement | null {
}

export function getClientRectangle (el: HTMLElement): DOMRect {
return el.getClientRects()[0] ?? el.getBoundingClientRect();
const rects = el.getClientRects();

for (let i = 0; i < rects.length; i++) {
if (rects[i].height > 0 && rects[i].width > 0)
return rects[i];
}
return el.getBoundingClientRect();
}

0 comments on commit c46f75d

Please sign in to comment.