Alfred-Skyblue / vue-draggable-plus

Universal Drag-and-Drop Component Supporting both Vue 3 and Vue 2
https://vue-draggable-plus.pages.dev/en/
MIT License
2.74k stars 105 forks source link

Possible Bug when after draging an element next elements creates in wrong position #42

Open jorge-plaza opened 10 months ago

jorge-plaza commented 10 months ago

When I swap two items being the one that I drag the one of the bottom, after the swap is made correclty, when I create a new Item in the list, this new item appear in the wrong place (under the item thet used to be the last, see images). The list of elements is in the right order when I log it to the console.

List inital state Initial state

After items 3-2 swapped dragging the inial item 3 to the 2 place (check coordinates for reference) After move

New item 4 created in the wrong place After new item

Interestingly if you swap the items the other way araund it wokrs fine. This is my code simplified

<div>
  <VueDraggable ref="el" v-if="matrix[index]" v-model="matrix[index].elements" :animation="150" handle=".handle"
    @update="updateList(index)"
    >
    <div v-for="(item, index) in matrix[index].elements" :key="index" 
        <p>{{ index + 1 }}.</p>
        <i class="fa-solid fa-bars handle cursor-move" style="color: #df0024"></i>
        ({{item}})
    </div>
  </VueDraggable>
</div>

Note that the matrix is an Vue Ref<Element[][]> injected in the component.