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 resizer on absolute drag mode when the parent is positioned ( position: relative | absolute | .... ) #6382

Merged
merged 5 commits into from
Feb 3, 2025
Merged
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: 20 additions & 2 deletions packages/core/src/utils/Resizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,13 @@ export default class Resizer {
const parentH = this.parentDim!.h;
const unitWidth = this.opts.unitWidth;
const unitHeight = this.opts.unitHeight;
const parentRect = this.getParentRect();
const startW = unitWidth === '%' ? (startDim.w / 100) * parentW : startDim.w;
const startH = unitHeight === '%' ? (startDim.h / 100) * parentH : startDim.h;

const box: RectDim = {
t: startDim.t,
l: startDim.l,
t: startDim.t - parentRect.top,
l: startDim.l - parentRect.left,
w: startW,
h: startH,
};
Expand Down Expand Up @@ -750,4 +752,20 @@ export default class Resizer {

return box;
}

getParentRect(): BoundingRect {
let parentRect = { left: 0, top: 0, width: 0, height: 0 };
const { el } = this;

if (!el) return parentRect;

const { offsetParent } = el;

// Check if the parent or any ancestor has `position: relative`, `absolute`, `fixed`, or `sticky`
if (offsetParent && offsetParent.tagName !== 'BODY') {
parentRect = this.getElementPos(offsetParent as HTMLElement);
}

return parentRect;
}
}