Skip to content

Commit 3a4c6bf

Browse files
feat: allow useAutoAnimate with Vue component ref (#186)
This adds support for using `useAutoAnimate` with a component as the parent. When you add `ref="parent"` to a component, the element is found at `parent.value.$el`. This update checks for component elements or a plain HTML element ref.
1 parent e7ebb71 commit 3a4c6bf

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/vue/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ export function useAutoAnimate<T extends Element>(
3939
}
4040
onMounted(() => {
4141
watchEffect(() => {
42-
if (element.value instanceof HTMLElement)
43-
controller = autoAnimate(element.value, options || {})
42+
const el = element.value?.$el || element.value
43+
if (el instanceof HTMLElement)
44+
controller = autoAnimate(el, options || {})
4445
})
4546
})
4647
onBeforeUnmount(() => {

0 commit comments

Comments
 (0)