Skip to content

Commit

Permalink
fix(onScrollLock): cache the el initial overflow value (#3527)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed Nov 9, 2023
1 parent 931b279 commit 038666b
Showing 1 changed file with 6 additions and 2 deletions.
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

0 comments on commit 038666b

Please sign in to comment.