Skip to content

Commit

Permalink
fix(PointerMoveTracker): fix `Unable to preventDefault inside passive…
Browse files Browse the repository at this point in the history
… event listener` (#76)
  • Loading branch information
simonguo committed Feb 29, 2024
1 parent 428aaa3 commit e2b5a4d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/PointerMoveTracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import on from './on';
import isEventSupported from './utils/isEventSupported';

interface PointerMoveTrackerOptions {
useTouchEvent: boolean;
useTouchEvent?: boolean;
onMove: (x: number, y: number, event: MouseEvent | TouchEvent) => void;
onMoveEnd: (event: MouseEvent | TouchEvent) => void;
}
Expand Down Expand Up @@ -63,13 +63,13 @@ export default class PointerMoveTracker {
*/
captureMoves(event) {
if (!this.eventMoveToken && !this.eventUpToken) {
this.eventMoveToken = on(this.domNode, 'mousemove', this.onDragMove);
this.eventUpToken = on(this.domNode, 'mouseup', this.onDragUp);

if (this.isSupportTouchEvent()) {
this.eventMoveToken = on(this.domNode, 'touchmove', this.onDragMove, { passive: false });
this.eventUpToken = on(this.domNode, 'touchend', this.onDragUp, { passive: false });
on(this.domNode, 'touchcancel', this.releaseMoves);
} else {
this.eventMoveToken = on(this.domNode, 'mousemove', this.onDragMove);
this.eventUpToken = on(this.domNode, 'mouseup', this.onDragUp);
}
}

Expand All @@ -81,7 +81,9 @@ export default class PointerMoveTracker {
this.y = this.getClientY(event);
}

event.preventDefault();
if (event.cancelable) {
event.preventDefault();
}
}

/**
Expand Down Expand Up @@ -135,7 +137,10 @@ export default class PointerMoveTracker {
this.y = y;

this.moveEvent = event;
event.preventDefault();

if (event.cancelable) {
event.preventDefault();
}
};

didDragMove = () => {
Expand Down

0 comments on commit e2b5a4d

Please sign in to comment.