Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(onScrollLock): cache the el initial overflow value #3527

Merged
merged 7 commits into from Nov 9, 2023
8 changes: 6 additions & 2 deletions packages/core/useScrollLock/index.ts
Expand Up @@ -44,6 +44,8 @@ function preventDefault(rawEvent: TouchEvent): boolean {
return false
}

const elInitialOverflow = new WeakMap<HTMLElement, CSSStyleDeclaration['overflow']>()

/**
* Lock scrolling of the element.
*
Expand All @@ -62,7 +64,8 @@ export function useScrollLock(
const target = resolveElement(toValue(el))
if (target) {
const ele = target as HTMLElement
initialOverflow = ele.style.overflow
if (!elInitialOverflow.get(ele))
elInitialOverflow.set(ele, initialOverflow)
if (isLocked.value)
ele.style.overflow = 'hidden'
}
Expand Down Expand Up @@ -91,7 +94,8 @@ export function useScrollLock(
if (!el || !isLocked.value)
return
isIOS && stopTouchMoveListener?.()
el.style.overflow = initialOverflow
el.style.overflow = elInitialOverflow.get(el as HTMLElement) ?? ''
elInitialOverflow.delete(el as HTMLElement)
isLocked.value = false
}

Expand Down