react-draggable icon indicating copy to clipboard operation
react-draggable copied to clipboard

DefaultPosition uses a different Y than onDrag?

Open spaasis opened this issue 10 years ago • 3 comments

Hi,

I was trying to save my draggable's position by storing the coordinates as such:

onDrag = (e, ui) => {

        this.props.state.x = e.clientX;
        this.props.state.y = e.clientY;
 }

And to use those values when loading the saved item:

<Draggable
   handle={'.dragDiv'}
   bounds={'parent'}
   defaultPosition={{ x: this.props.state.x, y: this.props.state.y }}
   onDrag={this.onDrag}
   onStop={this.onDragStop}>

When I dragged the draggable to the top left, the state was {x:0, y:0} as expected. However, when loading the component again, the component appeared in the middle left of the page instead of top left.

Is this intended behavior? Or is there maybe something wrong with my parent element's settings?

EDIT: I was able to solve the issue by using absolute positioning and left-top-values, but I think it would be much cleaner to use defaultPosition.

spaasis avatar Aug 04 '16 06:08 spaasis

I am having issues with defaultPosition as well - it is simply ignored in most cases, so definitely a bug.

grimen avatar Aug 11 '16 17:08 grimen

Returning to this after a long time.

The correct solution is to use ui.x and ui.y instead of the data contained in the event itself.

spaasis avatar Oct 05 '16 16:10 spaasis

Getting the same issue, ui.x and ui.y is doesn't works properly with default position.

oyesameed avatar Oct 06 '21 12:10 oyesameed