Skip to content

Commit 3cb6c3a

Browse files
committed
fix(date-picker): prevent browser pull-to-refresh behavior in calendar dialog by adjusting touch event handling
1 parent 69879f7 commit 3cb6c3a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/components/date-picker/date-picker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ export class DatePicker extends HTMLElement implements EventListenerObject {
401401
touchStartY = e.touches[0].clientY;
402402
touchStartX = e.touches[0].clientX;
403403
initialTouchTime = Date.now();
404-
}, { passive: true });
404+
}, { passive: false });
405405

406406
this.dialogElement.addEventListener('touchmove', (e: TouchEvent) => {
407407
if (window.matchMedia('(max-width: 768px)').matches) {
@@ -410,6 +410,12 @@ export class DatePicker extends HTMLElement implements EventListenerObject {
410410
const deltaY = touchY - touchStartY;
411411
const deltaX = touchX - touchStartX;
412412

413+
// Prevent pull-to-refresh when swiping inside the calendar dialog
414+
// This prevents the browser's native pull-to-refresh behavior
415+
if (deltaY > 0) {
416+
e.preventDefault();
417+
}
418+
413419
// If swiping down, add a visual feedback by following the finger
414420
if (deltaY > 0 && Math.abs(deltaY) > Math.abs(deltaX)) {
415421
this.dialogElement.style.transform = `translateY(${deltaY / 3}px)`;
@@ -422,7 +428,7 @@ export class DatePicker extends HTMLElement implements EventListenerObject {
422428
this.calendarElement.style.opacity = `${1 - (Math.abs(deltaX) / 500)}`;
423429
}
424430
}
425-
}, { passive: true });
431+
}, { passive: false });
426432

427433
this.dialogElement.addEventListener('touchend', (e: TouchEvent) => {
428434
if (window.matchMedia('(max-width: 768px)').matches) {

0 commit comments

Comments
 (0)