-
Notifications
You must be signed in to change notification settings - Fork 989
Closed as duplicate of#5818
Closed as duplicate of#5818
Copy link
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existstriageAwaiting initial review and prioritizationAwaiting initial review and prioritization
Description
Description
When using useSortable (SortableJS / VueUse) with UAccordion, sorting works initially, but adding a new item after sorting causes it to appear in an incorrect position in the UI, even though the underlying array order is correct.
This seems to be caused by a DOM ↔ Vue state desynchronization related to how UAccordion renders its internal structure.
Reproduction
<UAccordion
ref="accordion"
:items="items"
/>
<script setup>
useSortable(accordion, items, { animation: 150 })
</script>Steps:
- Render a single
UAccordionwith anitemsarray - Attach
useSortableto it - Reorder items via drag & drop
- Push a new item to the array
Result: new item renders in a random position in the UI.
Root Cause
useSortable/ SortableJS mutates DOM directlyUAccordionis a single component that renders its items internally- The
refpoints to the component instance, not the actual sortable DOM children - Vue is not aware of DOM reordering done by SortableJS
When Vue re-renders after adding an item, the DOM no longer matches Vue’s expectations.
Working Workaround
Render one accordion per item so each is a direct DOM child:
<div ref="sortableContainer">
<UAccordion
v-for="item in items"
:key="item.id"
:items="[item]"
/>
</div>
<script setup>
useSortable(sortableContainer, items, { animation: 150 })
</script>This works because SortableJS can safely operate on direct DOM children and Vue can correctly track them via keys.
Suggestion
- Document that
UAccordionis not compatible withuseSortablewhen using theitemsprop - Or expose refs / slots that allow sortable-friendly DOM structures
Environment
@nuxt/ui: v3- Vue: 3.x
- SortableJS via VueUse
Metadata
Metadata
Assignees
Labels
duplicateThis issue or pull request already existsThis issue or pull request already existstriageAwaiting initial review and prioritizationAwaiting initial review and prioritization