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(useScrollLock): fix iOS touchmove bug #2362

Merged
merged 12 commits into from Jan 3, 2023
9 changes: 7 additions & 2 deletions packages/core/useScrollLock/index.ts
Expand Up @@ -4,8 +4,13 @@ import { isIOS, resolveRef, resolveUnref, tryOnScopeDispose } from '@vueuse/shar

import { useEventListener } from '../useEventListener'

function preventDefault(rawEvent: TouchEvent): boolean {
function preventDefault(rawEvent: TouchEvent, ele: Element): boolean {
const e = rawEvent || window.event

// Do not prevent if the event is fired from a child.
if (ele !== e.target)
return false

// Do not prevent if the event has more than one touch (usually meaning this is a multi touch gesture like pinch to zoom).
if (e.touches.length > 1)
return true
Expand Down Expand Up @@ -49,7 +54,7 @@ export function useScrollLock(
stopTouchMoveListener = useEventListener(
ele,
'touchmove',
preventDefault,
(e) => { preventDefault(e as TouchEvent, ele) },
{ passive: false },
)
}
Expand Down