Skip to content

Commit

Permalink
feat: add info for touch events
Browse files Browse the repository at this point in the history
  • Loading branch information
danielkaradachki committed Jul 24, 2018
1 parent 7f4ad15 commit 390139a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 16 additions & 0 deletions e2e/draggable-compat.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('Draggable with Mouse and Touch events fallback', () => {
expect(args.pageY).toEqual(200);
});

it("isTouch is false for mouse events", () => {
mousedown(el, 100, 200);

const args = handler.calls.mostRecent().args[0];

expect(args.isTouch).toBeFalsy();
});

it('executes press with key modifiers on mousedown', () => {
mousedown(el, 100, 200);

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

it("isTouch is true for touch events", () => {
touchstart(el, 100, 200);

const args = handler.calls.mostRecent().args[0];

expect(args.isTouch).toBe(true);
});

it("executes press with originalEvent on touchstart", () => {
touchstart(el, 100, 200);

Expand Down
8 changes: 8 additions & 0 deletions e2e/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ describe('Draggable with Pointer events', () => {
expect(args.pageY).toEqual(200);
});

it("isTouch is false for pointer events", () => {
pointerdown(el, 100, 200);

const args = handler.calls.mostRecent().args[0];

expect(args.isTouch).toBeFalsy();
});

it("does not execute press if the left button is not clicked", () => {
pointerdown(el, 100, 200, true, 2);

Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function normalizeEvent(e) {
clientX: e.changedTouches[0].clientX,
clientY: e.changedTouches[0].clientY,
type: e.type,
originalEvent: e
originalEvent: e,
isTouch: true
};
}

Expand Down

0 comments on commit 390139a

Please sign in to comment.