Skip to content

Commit

Permalink
fix(useSortable): order of dom and array is different (#2926)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alfred-Skyblue committed Apr 12, 2023
1 parent e6e2576 commit 3a50893
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/integrations/useSortable/index.ts
@@ -1,6 +1,7 @@
import { defaultDocument, resolveUnref, tryOnMounted, tryOnScopeDispose, unrefElement } from '@vueuse/core'
import type { ConfigurableDocument, MaybeComputedRef } from '@vueuse/core'
import Sortable, { type Options } from 'sortablejs'
import { nextTick } from 'vue-demi'

export interface UseSortableReturn {
/**
Expand Down Expand Up @@ -62,6 +63,8 @@ export function moveArrayElement<T>(
to: number,
): void {
const array = resolveUnref(list)
if (to >= 0 && to < array.length)
array.splice(to, 0, array.splice(from, 1)[0])
if (to >= 0 && to < array.length) {
const element = array.splice(from, 1)[0]
nextTick(() => array.splice(to, 0, element))
}
}

0 comments on commit 3a50893

Please sign in to comment.