Skip to content

Commit 8bffe78

Browse files
committed
Prevent Safari back gesture in mobile nav
Adds e.preventDefault() to block Safari's back navigation gesture on iOS when opening the mobile nav. Sets touchstart event listener to passive: false to allow preventDefault().
1 parent d6e48c6 commit 8bffe78

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/lib/components/MobileNav.svelte

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@
102102
// Exception: overlay tap (no scroll content, so no direction conflict)
103103
if (!isOpen && touch.clientX < 40) {
104104
// Opening gesture - wait for direction lock before starting drag
105+
// Prevent Safari's back navigation gesture on iOS
106+
e.preventDefault();
105107
potentialDrag = true;
106108
dragStartedOpen = false;
107109
} else if (isOpen && !touchOnDrawer) {
@@ -197,7 +199,8 @@
197199
}
198200
199201
onMount(() => {
200-
window.addEventListener("touchstart", onTouchStart, { passive: true });
202+
// touchstart needs passive: false to allow preventDefault() for Safari back gesture
203+
window.addEventListener("touchstart", onTouchStart, { passive: false });
201204
window.addEventListener("touchmove", onTouchMove, { passive: true });
202205
window.addEventListener("touchend", onTouchEnd, { passive: true });
203206
window.addEventListener("touchcancel", onTouchCancel, { passive: true });

0 commit comments

Comments
 (0)