diff --git a/src/index.tsx b/src/index.tsx index 4c8ebd22..9f73bbc0 100755 --- a/src/index.tsx +++ b/src/index.tsx @@ -234,12 +234,10 @@ export class Rnd extends React.PureComponent { } componentDidMount() { - this.updateOffsetFromParent(); - const { left, top } = this.offsetFromParent; const { x, y } = this.getDraggablePosition(); this.draggable.setState({ - x: x - left, - y: y - top, + x, + y, }); // HACK: Apply position adjustment this.forceUpdate(); @@ -360,9 +358,19 @@ export class Rnd extends React.PureComponent { if (!this.props.dragAxis || this.props.dragAxis === "both") { return this.props.onDrag(e, { ...data, x: data.x + left, y: data.y + top }); } else if (this.props.dragAxis === "x") { - return this.props.onDrag(e, { ...data, x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 }); + return this.props.onDrag(e, { + ...data, + x: data.x + left, + y: this.originalPosition.y + top, + deltaY: 0, + }); } else if (this.props.dragAxis === "y") { - return this.props.onDrag(e, { ...data, x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 }); + return this.props.onDrag(e, { + ...data, + x: this.originalPosition.x + left, + y: data.y + top, + deltaX: 0, + }); } } @@ -370,11 +378,25 @@ export class Rnd extends React.PureComponent { if (!this.props.onDragStop) return; const { left, top } = this.offsetFromParent; if (!this.props.dragAxis || this.props.dragAxis === "both") { - return this.props.onDragStop(e, { ...data, x: data.x + left, y: data.y + top }); + return this.props.onDragStop(e, { + ...data, + x: data.x + left, + y: data.y + top, + }); } else if (this.props.dragAxis === "x") { - return this.props.onDragStop(e, { ...data, x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 }); + return this.props.onDragStop(e, { + ...data, + x: data.x + left, + y: this.originalPosition.y + top, + deltaY: 0, + }); } else if (this.props.dragAxis === "y") { - return this.props.onDragStop(e, { ...data, x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 }); + return this.props.onDragStop(e, { + ...data, + x: this.originalPosition.x + left, + y: data.y + top, + deltaX: 0, + }); } }