Skip to content

Commit 72c8876

Browse files
committed
Component change the Y / X position when Drag stops even though dragging is restricted to X/Y axis
1 parent c231083 commit 72c8876

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

src/index.tsx

+26-4
Original file line numberDiff line numberDiff line change
@@ -497,10 +497,32 @@ export class Rnd extends React.Component<Props, State> {
497497
const { left, top } = this.getOffsetFromParent();
498498
let draggablePosition;
499499
if (position) {
500-
draggablePosition = {
501-
x: position.x - left,
502-
y: position.y - top,
503-
};
500+
switch (dragAxis) {
501+
case "x":
502+
draggablePosition = {
503+
x: position.x - left,
504+
y: position.y,
505+
};
506+
break;
507+
case "y":
508+
draggablePosition = {
509+
x: position.x,
510+
y: position.y - top,
511+
};
512+
break;
513+
case "none":
514+
draggablePosition = {
515+
x: position.x,
516+
y: position.y,
517+
};
518+
break;
519+
default:
520+
draggablePosition = {
521+
x: position.x - left,
522+
y: position.y - top,
523+
};
524+
break;
525+
}
504526
}
505527
return (
506528
<Draggable

0 commit comments

Comments
 (0)