Skip to content

Commit 5befb90

Browse files
committed
Fix: Prevent viewer from opening during swiper drag
1 parent 739662d commit 5befb90

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

src/components/swiper/cc-swiper.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class CcSwiper extends ChuciElement {
1313
private divPagination?: HTMLDivElement
1414
private divPrevious?: HTMLDivElement
1515
private divNext?: HTMLDivElement
16+
private isDragging = false
1617

1718
static get observedAttributes() {
1819
return ['has-thumb', 'autoplay']
@@ -282,6 +283,12 @@ export class CcSwiper extends ChuciElement {
282283
img.addEventListener('dragstart', (e) => e.preventDefault())
283284

284285
img.addEventListener('click', (e) => {
286+
// Ignore click if user was dragging
287+
if (this.isDragging) {
288+
this.isDragging = false
289+
return
290+
}
291+
285292
e.preventDefault()
286293
e.stopPropagation()
287294
e.stopImmediatePropagation()
@@ -346,7 +353,18 @@ export class CcSwiper extends ChuciElement {
346353
preventClicksPropagation: false,
347354
simulateTouch: true,
348355
allowTouchMove: true,
349-
loop: slidesLoop
356+
loop: slidesLoop,
357+
on: {
358+
sliderMove: () => {
359+
this.isDragging = true
360+
},
361+
touchEnd: () => {
362+
// Reset dragging flag after a short delay to allow click event to check it
363+
setTimeout(() => {
364+
this.isDragging = false
365+
}, 50)
366+
}
367+
}
350368
})
351369
}
352370
}

0 commit comments

Comments
 (0)