Skip to content

Commit

Permalink
fix-boundary-scale: adds scaling to boundary Fixes #820 (#821)
Browse files Browse the repository at this point in the history
* fix-boundary-scale: adds scaling to boundary

* clean up code, fix ts undefined error

---------

Co-authored-by: Kyle McArthur <[email protected]>
Co-authored-by: kyle mcarthur <[email protected]>
  • Loading branch information
3 people authored Sep 10, 2024
1 parent 57d116f commit ded2aa0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -650,30 +650,32 @@ export class Resizable extends React.PureComponent<ResizableProps, State> {
}

setBoundingClientRect() {
const adjustedScale = 1 / (this.props.scale || 1);

// For parent boundary
if (this.props.bounds === 'parent') {
const parent = this.parentNode;
if (parent) {
const parentRect = parent.getBoundingClientRect();
this.parentLeft = parentRect.left;
this.parentTop = parentRect.top;
this.parentLeft = parentRect.left * adjustedScale;
this.parentTop = parentRect.top * adjustedScale;
}
}

// For target(html element) boundary
if (this.props.bounds && typeof this.props.bounds !== 'string') {
const targetRect = this.props.bounds.getBoundingClientRect();
this.targetLeft = targetRect.left;
this.targetTop = targetRect.top;
this.targetLeft = targetRect.left * adjustedScale;
this.targetTop = targetRect.top * adjustedScale;
}

// For boundary
if (this.resizable) {
const { left, top, right, bottom } = this.resizable.getBoundingClientRect();
this.resizableLeft = left;
this.resizableRight = right;
this.resizableTop = top;
this.resizableBottom = bottom;
this.resizableLeft = left * adjustedScale;
this.resizableRight = right * adjustedScale;
this.resizableTop = top * adjustedScale;
this.resizableBottom = bottom * adjustedScale;
}
}

Expand Down

0 comments on commit ded2aa0

Please sign in to comment.