Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(useSortable): prevent from creating multi instances #3501

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/integrations/useSortable/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function useSortable<T>(
list: MaybeRefOrGetter<T[]>,
options: UseSortableOptions = {},
): UseSortableReturn {
let sortable: Sortable
let sortable: Sortable | undefined

const { document = defaultDocument, ...resetOptions } = options

Expand All @@ -51,12 +51,15 @@ export function useSortable<T>(

const start = () => {
const target = (typeof el === 'string' ? document?.querySelector(el) : unrefElement(el))
if (!target)
if (!target || sortable !== undefined)
Doctor-wu marked this conversation as resolved.
Show resolved Hide resolved
return
sortable = new Sortable(target as HTMLElement, { ...defaultOptions, ...resetOptions })
}

const stop = () => sortable?.destroy()
const stop = () => {
sortable?.destroy()
sortable = undefined
}

const option = <K extends keyof Options>(name: K, value?: Options[K]) => {
if (value !== undefined)
Expand Down