Skip to content

Commit

Permalink
fix(useScrollLock): should work normal with initialState (vitest-dev#…
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Mar 2, 2022
1 parent 3fa0d10 commit 75146b8
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core/useScrollLock/index.ts
@@ -1,4 +1,4 @@
import { computed, ref, unref } from 'vue-demi'
import { computed, ref, unref, watch } from 'vue-demi'
import type { Fn, MaybeRef } from '@vueuse/shared'
import { isClient } from '@vueuse/shared'
import { useEventListener } from '../useEventListener'
Expand Down Expand Up @@ -30,10 +30,19 @@ export function useScrollLock(
let touchMoveListener: Fn | null = null
let initialOverflow: CSSStyleDeclaration['overflow']

watch(() => unref(element), (el) => {
if (el) {
const ele = el as HTMLElement
initialOverflow = ele.style.overflow
if (isLocked.value) ele.style.overflow = 'hidden'
}
}, {
immediate: true,
})

const lock = () => {
const ele = (unref(element) as HTMLElement)
if (!ele || isLocked.value) return
initialOverflow = ele.style.overflow
if (isIOS) {
touchMoveListener = useEventListener(
document,
Expand Down

0 comments on commit 75146b8

Please sign in to comment.