Skip to content

Commit 1f79b71

Browse files
committed
feat: update useInView to accept root as MaybeRef
1 parent 9096c4f commit 1f79b71

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/motion/src/utils/use-in-view.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ import type { Options } from '@/types/state'
44
import { inView } from 'framer-motion/dom'
55
import type { MaybeRef } from '@vueuse/core'
66

7+
type InViewOptions = Options['inViewOptions']
8+
export interface UseInViewOptions extends Omit<InViewOptions, 'root'> {
9+
root?: MaybeRef<Element | Document>
10+
}
11+
712
export function useInView<T extends Element = any>(
813
domRef: Ref<T | null>,
9-
options?: MaybeRef<Options['inViewOptions']>,
14+
options?: MaybeRef<UseInViewOptions>,
1015
) {
1116
const isInView = ref(false)
1217

@@ -24,7 +29,10 @@ export function useInView<T extends Element = any>(
2429
isInView.value = false
2530
}
2631
}
27-
const cleanup = inView(domRef.value, onEnter, realOptions)
32+
const cleanup = inView(domRef.value, onEnter, {
33+
...realOptions,
34+
root: unref(realOptions.root),
35+
})
2836
onCleanup(() => {
2937
cleanup()
3038
})

0 commit comments

Comments
 (0)