Browse Source

Fix resizer on absolute drag mode when the parent is positioned ( position: relative | absolute | .... ) (#6382)

* Fix resizer on absolute drag mode when the parent is positioned ( position: relative | absolute | .... )

* Improve calculation performance

* Up Resizer

---------

Co-authored-by: Artur Arseniev <artur.catch@hotmail.it>
pull/6398/head
mohamed yahia 1 year ago
committed by GitHub
parent
commit
4d34f527a2
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 22
      packages/core/src/utils/Resizer.ts

22
packages/core/src/utils/Resizer.ts

@ -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,
};
@ -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;
}
}

Loading…
Cancel
Save