Skip to content

Commit

Permalink
Fix duplicated instances when dragging sortable with sortable childs
Browse files Browse the repository at this point in the history
  • Loading branch information
james-em committed Apr 29, 2024
1 parent 413b340 commit 1b57701
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ export default class StimulusSortable extends Controller<HTMLElement> {
}

connect() {
this.sortable = new Sortable(this.element, {
...this.defaultOptions,
...this.options,
})
if (Sortable.active) {
this.sortable = Sortable.get(this.element)
} else {
this.sortable = new Sortable(this.element, {
...this.defaultOptions,
...this.options,
})
}
}

disconnect() {
this.sortable.destroy()
this.sortable = undefined
if (!Sortable.active) {
this.sortable.destroy()
this.sortable = undefined
}
}

async onUpdate({ item, newIndex }) {
Expand Down

0 comments on commit 1b57701

Please sign in to comment.