Skip to content

Commit

Permalink
Merge pull request #1541 from clauderic/handle-cancel-events
Browse files Browse the repository at this point in the history
Handle touch and pointer cancel events
  • Loading branch information
clauderic authored Nov 23, 2024
2 parents 2eb636f + 99643f6 commit b7f46bb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/handle-cancel-events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@dnd-kit/core': patch
---

Handle `touchcancel` and `pointercancel` events.
6 changes: 6 additions & 0 deletions packages/core/src/sensors/pointer/AbstractPointerSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface EventDescriptor {
}

export interface PointerEventHandlers {
cancel?: EventDescriptor;
move: EventDescriptor;
end: EventDescriptor;
}
Expand Down Expand Up @@ -109,6 +110,11 @@ export class AbstractPointerSensor implements SensorInstance {

this.listeners.add(events.move.name, this.handleMove, {passive: false});
this.listeners.add(events.end.name, this.handleEnd);

if (events.cancel) {
this.listeners.add(events.cancel.name, this.handleCancel);
}

this.windowListeners.add(EventName.Resize, this.handleCancel);
this.windowListeners.add(EventName.DragStart, preventDefault);
this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/sensors/pointer/PointerSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from './AbstractPointerSensor';

const events: PointerEventHandlers = {
cancel: {name: 'pointercancel'},
move: {name: 'pointermove'},
end: {name: 'pointerup'},
};
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/sensors/touch/TouchSensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import type {SensorProps} from '../types';

const events: PointerEventHandlers = {
cancel: {name: 'touchcancel'},
move: {name: 'touchmove'},
end: {name: 'touchend'},
};
Expand Down

0 comments on commit b7f46bb

Please sign in to comment.