Skip to content

Commit d6af877

Browse files
committed
Move click/tap events to onClick handler to fix bug with double tapping on mobile chrome.
1 parent fc308b3 commit d6af877

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/core/events/onClick.mjs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1+
import { now } from '../../shared/utils.mjs';
2+
13
export default function onClick(e) {
24
const swiper = this;
5+
const data = swiper.touchEventsData;
6+
37
if (!swiper.enabled) return;
48
if (!swiper.allowClick) {
59
if (swiper.params.preventClicks) e.preventDefault();
610
if (swiper.params.preventClicksPropagation && swiper.animating) {
711
e.stopPropagation();
812
e.stopImmediatePropagation();
913
}
14+
} else {
15+
const clickTime = now();
16+
const pathTree = e.path || e.composedPath?.();
17+
18+
swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
19+
swiper.emit('tap click', e);
20+
21+
if (clickTime - data.lastClickTime < 300) {
22+
swiper.emit('doubleTap doubleClick', e);
23+
}
24+
25+
data.lastClickTime = now();
1026
}
1127
}

src/core/events/onTouchEnd.mjs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { now, nextTick } from '../../shared/utils.mjs';
1+
import { nextTick } from '../../shared/utils.mjs';
22

33
export default function onTouchEnd(event) {
44
const swiper = this;
@@ -55,21 +55,6 @@ export default function onTouchEnd(event) {
5555
swiper.setGrabCursor(false);
5656
}
5757

58-
// Time diff
59-
const touchEndTime = now();
60-
const timeDiff = touchEndTime - data.touchStartTime;
61-
62-
// Tap, doubleTap, Click
63-
if (swiper.allowClick) {
64-
const pathTree = e.path || (e.composedPath && e.composedPath());
65-
swiper.updateClickedSlide((pathTree && pathTree[0]) || e.target, pathTree);
66-
swiper.emit('tap click', e);
67-
if (timeDiff < 300 && touchEndTime - data.lastClickTime < 300) {
68-
swiper.emit('doubleTap doubleClick', e);
69-
}
70-
}
71-
72-
data.lastClickTime = now();
7358
nextTick(() => {
7459
if (!swiper.destroyed) swiper.allowClick = true;
7560
});

0 commit comments

Comments
 (0)