import { enableBodyScroll , disableBodyScroll , BodyScrollOptions , } from "body-scroll-lock" ; import { Ref , watch } from "vue" ; import { useRef } from "@chakra-ui/vue-utils" ; param enable param options returns export function useBodyScrollLock ( enable , options ? ) { const [ scrollLockRef , scrollLockEl ] = useRef ( ) ; watch ( [ scrollLockEl , enable ] , ( [ target , isActive ] , [ previousTarget ] ) => { if ( ! target || ! enable . value ) { previousTarget && enableBodyScroll ( previousTarget ) ; } else if ( target && isActive ) { disableBodyScroll ( target , options ) ; } else { enableBodyScroll ( target ) ; } } , { immediate : true , flush : "post" , } ) ; return { scrollLockRef , } ; }