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 0184d37
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,20 @@ 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()
if (!Sortable.active) {
this.sortable.destroy()
}
this.sortable = undefined
}

Expand Down

0 comments on commit 0184d37

Please sign in to comment.