Skip to content

Commit

Permalink
fix: do not fire drag on pointermove before press
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvetomir committed Nov 24, 2017
1 parent 26ad6d4 commit 5025215
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions e2e/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ describe('Draggable with Pointer events', () => {
});

describe("Drag", () => {
const drag = () => {
pointerdown(el, 100, 200);
pointermove(el, 101, 201);
};

beforeEach(() => {
handler = jasmine.createSpy("onDrag");

Expand All @@ -70,30 +75,35 @@ describe('Draggable with Pointer events', () => {
});

draggable.bindTo(el);

pointerdown(el, 100, 200);
pointermove(el, 101, 201);
});

it("triggers drag for down + move", () => {
drag();
expect(handler).toHaveBeenCalled();
});

it("executes drag with offset on pointermove", () => {
drag();
const args = handler.calls.mostRecent().args[0];

expect(100 - Math.abs(args.offsetX)).toBeLessThan(10);
expect(200 - Math.abs(args.offsetY)).toBeLessThan(10);
});

it("disposes drag handlers properly", () => {
drag();
draggable.destroy();
draggable = null;

pointermove(el, 101, 201);

expect(handler).toHaveBeenCalledTimes(1);
});

it("does not trigger drag before press", () => {
pointermove(el, 101, 201);
expect(handler).not.toHaveBeenCalled();
});
});

describe("Release", () => {
Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class Draggable {

this._pointerdown = (e) => {
if (e.isPrimary) {
bind(this._element, "pointermove", this._pointermove);
this._touchAction = e.target.style.touchAction;
e.target.style.touchAction = "none";
e.target.setPointerCapture(e.pointerId);
Expand All @@ -114,6 +115,7 @@ export class Draggable {

this._pointerup = (e) => {
if (e.isPrimary) {
unbind(this._element, "pointermove", this._pointermove);
e.target.style.touchAction = this._touchAction;
this._releaseHandler(e);
}
Expand All @@ -133,7 +135,6 @@ export class Draggable {

if (Draggable.supportPointerEvent()) {
bind(element, "pointerdown", this._pointerdown);
bind(element, "pointermove", this._pointermove);
bind(element, "pointerup", this._pointerup);
} else {
bind(element, "mousedown", this._mousedown);
Expand Down

0 comments on commit 5025215

Please sign in to comment.