File tree 2 files changed +31
-4
lines changed
Filter options
packages/integrations/useSortable
2 files changed +31
-4
lines changed
Original file line number Diff line number Diff line change 1
1
import { mount } from '@vue/test-utils'
2
- import { templateRef } from '@vueuse/core'
2
+ import { templateRef , unrefElement } from '@vueuse/core'
3
3
import Sortable from 'sortablejs'
4
4
import { describe , expect , it } from 'vitest'
5
5
import { defineComponent , shallowRef } from 'vue'
@@ -152,4 +152,31 @@ describe('useSortable', () => {
152
152
}
153
153
} )
154
154
} )
155
+
156
+ it ( 'accepts component refs' , ( ) => {
157
+ const SubComponent = defineComponent ( {
158
+ template : '<p>foo</p>' ,
159
+ } )
160
+ const wrapper = mount ( defineComponent ( {
161
+ components : { SubComponent } ,
162
+ template : '<SubComponent ref="el"></SubComponent>' ,
163
+ setup ( ) {
164
+ const el = templateRef < InstanceType < typeof SubComponent > > ( 'el' )
165
+ const list = shallowRef < string [ ] > ( [ ] )
166
+ const result = useSortable ( el , list , {
167
+ } )
168
+
169
+ return { ...result , el }
170
+ } ,
171
+ } ) )
172
+ const vm = wrapper . vm
173
+ try {
174
+ const el = unrefElement ( vm . el ) as HTMLElement
175
+ const sortable = Sortable . get ( el )
176
+ expect ( sortable ) . toBeDefined ( )
177
+ }
178
+ finally {
179
+ wrapper . unmount ( )
180
+ }
181
+ } )
155
182
} )
Original file line number Diff line number Diff line change 1
- import type { ConfigurableDocument } from '@vueuse/core'
1
+ import type { ConfigurableDocument , MaybeElement } from '@vueuse/core'
2
2
import type { Options } from 'sortablejs'
3
3
import type { MaybeRef , MaybeRefOrGetter } from 'vue'
4
4
import { defaultDocument , tryOnMounted , tryOnScopeDispose , unrefElement } from '@vueuse/core'
@@ -27,7 +27,7 @@ export type UseSortableOptions = Options & ConfigurableDocument
27
27
28
28
export function useSortable < T > ( selector : string , list : MaybeRefOrGetter < T [ ] > ,
29
29
options ?: UseSortableOptions ) : UseSortableReturn
30
- export function useSortable < T > ( el : MaybeRefOrGetter < HTMLElement | null | undefined > , list : MaybeRefOrGetter < T [ ] > ,
30
+ export function useSortable < T > ( el : MaybeRefOrGetter < MaybeElement > , list : MaybeRefOrGetter < T [ ] > ,
31
31
options ?: UseSortableOptions ) : UseSortableReturn
32
32
33
33
/**
@@ -37,7 +37,7 @@ export function useSortable<T>(el: MaybeRefOrGetter<HTMLElement | null | undefin
37
37
* @param options
38
38
*/
39
39
export function useSortable < T > (
40
- el : MaybeRefOrGetter < HTMLElement | null | undefined > | string ,
40
+ el : MaybeRefOrGetter < MaybeElement > | string ,
41
41
list : MaybeRefOrGetter < T [ ] > ,
42
42
options : UseSortableOptions = { } ,
43
43
) : UseSortableReturn {
You can’t perform that action at this time.
0 commit comments