Skip to content

Commit 34d4cee

Browse files
Copilotbrunoborges
andcommitted
Fix event handling to properly prevent navigation on tap/swipe
Co-authored-by: brunoborges <129743+brunoborges@users.noreply.github.com>
1 parent 67a6761 commit 34d4cee

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

app.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@
218218
const isHorizontalSwipe = absDeltaX > 50 && absDeltaX > absDeltaY;
219219

220220
if (isHorizontalSwipe) {
221+
// Prevent default navigation
222+
e.preventDefault();
221223
// Swipe left = show modern, swipe right = show old
222224
if (deltaX < 0) {
223225
// Swipe left - show modern
@@ -228,12 +230,13 @@
228230
}
229231
} else if (absDeltaX < 10 && absDeltaY < 10) {
230232
// It's a tap (movement under 10px threshold)
233+
e.preventDefault();
231234
card.classList.toggle('toggled');
232235
}
233-
}, { passive: true });
236+
}, { passive: false });
234237

235-
// Prevent click events from propagating when on touch devices
236-
// to avoid navigation when toggling
238+
// Prevent click events on card-code from navigating
239+
// (the touch handlers above already handle the interaction)
237240
card.addEventListener('click', (e) => {
238241
if (e.target.closest('.card-code')) {
239242
e.preventDefault();

0 commit comments

Comments
 (0)