question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting position on OnDragEnd has undefined behavior.

See original GitHub issue

here’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:closed
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
PuruVJcommented, Jun 14, 2022

Closing as unresponsive. Feel free to open if issue still here

0reactions
PuruVJcommented, Mar 18, 2022

OK I got the issue. It’s the issue when you don’t update x and y on onDrag 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

CleanShot 2022-03-18 at 13 12 26@2x

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found