Skip to content

Commit 390139a

Browse files
feat: add info for touch events
1 parent 7f4ad15 commit 390139a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

e2e/draggable-compat.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ describe('Draggable with Mouse and Touch events fallback', () => {
3939
expect(args.pageY).toEqual(200);
4040
});
4141

42+
it("isTouch is false for mouse events", () => {
43+
mousedown(el, 100, 200);
44+
45+
const args = handler.calls.mostRecent().args[0];
46+
47+
expect(args.isTouch).toBeFalsy();
48+
});
49+
4250
it('executes press with key modifiers on mousedown', () => {
4351
mousedown(el, 100, 200);
4452

@@ -66,6 +74,14 @@ describe('Draggable with Mouse and Touch events fallback', () => {
6674
expect(args.pageY).toEqual(200);
6775
});
6876

77+
it("isTouch is true for touch events", () => {
78+
touchstart(el, 100, 200);
79+
80+
const args = handler.calls.mostRecent().args[0];
81+
82+
expect(args.isTouch).toBe(true);
83+
});
84+
6985
it("executes press with originalEvent on touchstart", () => {
7086
touchstart(el, 100, 200);
7187

e2e/draggable.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ describe('Draggable with Pointer events', () => {
4040
expect(args.pageY).toEqual(200);
4141
});
4242

43+
it("isTouch is false for pointer events", () => {
44+
pointerdown(el, 100, 200);
45+
46+
const args = handler.calls.mostRecent().args[0];
47+
48+
expect(args.isTouch).toBeFalsy();
49+
});
50+
4351
it("does not execute press if the left button is not clicked", () => {
4452
pointerdown(el, 100, 200, true, 2);
4553

src/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function normalizeEvent(e) {
2222
clientX: e.changedTouches[0].clientX,
2323
clientY: e.changedTouches[0].clientY,
2424
type: e.type,
25-
originalEvent: e
25+
originalEvent: e,
26+
isTouch: true
2627
};
2728
}
2829

0 commit comments

Comments
 (0)