Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte smooth-dnd #98

Open
interk0t opened this issue Dec 20, 2023 · 0 comments
Open

Svelte smooth-dnd #98

interk0t opened this issue Dec 20, 2023 · 0 comments

Comments

@interk0t
Copy link

interk0t commented Dec 20, 2023

Hello! I understand that at the moment there are no components for Svelte, however, I would be satisfied with using it directly without them, if possible. The problem is that when I change the order of the elements in the array in the onDrop function, in the browser the moved element is returned to its original place (in the console in the array the order of the elements looks correct). And the moved element itself is returned exactly when I update the order of the elements in the array., where could there be an error? Thank you

`
<script lang='ts'>

  import smoothDnD from 'smooth-dnd';
  
     onMount(()=> {

    const containerElement = document.getElementById('boxId');
    const containerInstance = smoothDnD(containerElement, {
        orientation: 'vertical',
        behaviour: 'move',
        lockAxis: 'y',
        removeOnDropOut: true,
        dragBeginDelay: 0,
        animationDuration: 250,
        autoScrollEnabled: false,

        onDrop: function(dropResult) {
            const item = included[dropResult.removedIndex];
            included.splice(dropResult.removedIndex, 1);
            included.splice(dropResult.addedIndex, 0, item);

        },
        getChildPayload: function(i) {
            return { id: i, otherData: 'Other Data' };
        },

    });
    
})
    let included = [
    {  title: 'ITEM1', color: '#5aabff' },
    { title: 'ITEM2', color: '#5aff5d' },
    { title: 'ITEM23', color: '#ff5a5a'},
]
</script>

  <div class="box12"  id="boxId">
      {#each included as item }
          <div style="background-color: {item.color}" >{item.title}</div>
      {/each}
  </div>

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant