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

fix(grid): incorrect `x` and `y` passed to onStop

Open STRML opened this issue 4 years ago • 5 comments

This was caused by onStop erroneously recalculating coordinates, which is not necessary / should not happen in the real world, as mouseup and touchend should not pass clientX and clientY values meaningfully different than the last corresponding move event. In fact, they are already ignored by <Draggable>.

For this reason, we can simply trust the lastX and lastY in onDragStop, and pass those back.

Fixes #413, bokuweb/react-rnd#453

STRML avatar Jul 29 '20 21:07 STRML

@nicholaschiang could you verify this works for you - simply pin react-draggable to this git branch in your package.json resolutions?

"react-draggable": "git+https://[email protected]/strml/react-draggable.git#fix/grid-dragStop"

STRML avatar Jul 29 '20 21:07 STRML

Just added it @STRML and it looks like the issue is still there:

jumping

You'll notice how the draggable keeps jumping a couple of pixels after dropping (there are some other unrelated issues shown in that GIF too... feel free to ignore them until I finish debugging on my end).

nicholaschiang avatar Jul 30 '20 16:07 nicholaschiang

@STRML I also created a little repro of the same (or, at least, a similar) problem I was having when dynamically resizing the grid snap and RND size.

https://codesandbox.io/s/white-water-xrqp2?file=/src/index.js

You'll notice in that repro that the RND keeps jumping around and doesn't snap correctly to the resized grid (even though we're using the { x: data.lastX, y: data.lastY } workaround proposed in #413):

resizing-parent

Ideally, the X position should always be a multiple of the RND's width (displayed on the parent) and the Y position should always be a multiple of the RND's height (also displayed on the parent).

nicholaschiang avatar Jul 30 '20 16:07 nicholaschiang

Any idea on on a timeline for this? @STRML

trickpattyFH20 avatar Dec 10 '21 01:12 trickpattyFH20

@nicholaschiang could you verify this works for you - simply pin react-draggable to this git branch in your package.json resolutions?

"react-draggable": "git+https://[email protected]/strml/react-draggable.git#fix/grid-dragStop"

@STRML The repository does not exist at this link anymore. Also, when trying to use the grid-dragStop branch from this repo as an npm dependency, the source code for this repo is not included in ./node-modules because the package.json in react-grid-layout/react-draggable does not include ./lib in the files field, or have./build committed to that branch.

Could you merge a fix for this issue, or include the source code on that branch so that it can be used as a dependency?

trickpattyFH20 avatar Dec 29 '21 22:12 trickpattyFH20