Setting position on OnDragEnd has undefined behavior.
See original GitHub issuehere’s an example svelte component:
<script>
import { draggable } from '@neodrag/svelte'
let x = 100
let y = 100
function onDragEnd(e){
x = 300
y = 300
}
</script>
<div
use:draggable={{
position: { x, y },
onDragEnd,
}}
>
Say after I drop it, i want the component to move to (300,300). On first drag and drop, it works as expected. However, on subsequent ones, the component doesnt snap back to (300,300), it instead stays where it was dropped.
Furthermore, if this was:
function onDragEnd(e){
x = 0
y = 0
}
Then it doesnt even move the first time.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
React beautiful DnD drag out of position problem
Basically when the library is using position: fixed as OP mentioned, ... If any parent element has transform rule set to anything other...
Read more >Item being dragged is offset to the right instead of "inline". #499
When dragging an element, the element is positioned near the cursor. Actual behavior. The element is offset to the right by roughly 50%...
Read more >Adding drag-and-drop functionality with react-beautiful-dnd
See how to make your application powerful by animating it with the well-known drag-and-drop feature using the react-beautiful-dnd library.
Read more >Day 14 - Interactions 3 - Dragging / Tyler Wolf | Observable
We set the x and y positions of the rect so that it is centered on the position of the drag event (note...
Read more >Gesture options - @use-gesture documentation
touch-action: none is a common CSS property that you'll set on draggable items so that scroll doesn't interfere with the drag behavior on...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Closing as unresponsive. Feel free to open if issue still here
OK I got the issue. It’s the issue when you don’t update
x
andy
ononDrag
event.Svelte action can’t affect the upstream variable passed to it, so you have to update them manually by listening to onDrag event. In your example, it stays int the same place because x and y are 300 already, and setting them to 300 again won’t trigger any .
It’s listed here https://github.com/PuruVJ/neodrag/tree/main/packages/svelte#controlled-vs-uncontrolled