Skip to content

Commit 7be44a4

Browse files
committed
fix: 🐛 getBoundingRect not taking parents into account
1 parent 05a50e0 commit 7be44a4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@print-one/grapesjs",
33
"description": "Free and Open Source Web Builder Framework",
4-
"version": "0.21.19",
4+
"version": "0.21.20",
55
"author": "Print.one",
66
"license": "BSD-3-Clause",
77
"homepage": "http://grapesjs.com",

src/utils/dom.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,17 @@ export const isCommentNode = (el?: Node): el is Comment => el?.nodeType === Node
153153
export const isTaggableNode = (el?: Node) => el && !isTextNode(el) && !isCommentNode(el);
154154

155155
export const getBoundingRect = (el: HTMLElement) => {
156-
const top = el.offsetTop;
157-
const left = el.offsetLeft;
156+
let top = el.offsetTop;
157+
let left = el.offsetLeft;
158158
const width = el.offsetWidth;
159159
const height = el.offsetHeight;
160160

161+
let currentEl = el;
162+
while ((currentEl = currentEl.offsetParent as HTMLElement)) {
163+
top += currentEl.offsetTop;
164+
left += currentEl.offsetLeft;
165+
}
166+
161167
return {
162168
top,
163169
left,
@@ -168,7 +174,7 @@ export const getBoundingRect = (el: HTMLElement) => {
168174
x: left,
169175
y: top,
170176
};
171-
}
177+
};
172178

173179
/**
174180
* Get DOMRect of the element.

0 commit comments

Comments
 (0)