react-draggable
react-draggable copied to clipboard
fix(grid): incorrect `x` and `y` passed to onStop
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
@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"
Just added it @STRML and it looks like the issue is still there:
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).
@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):
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).
Any idea on on a timeline for this? @STRML
@nicholaschiang could you verify this works for you - simply pin
react-draggable
to this git branch in your package.jsonresolutions
?"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?