diff --git a/e2e/draggable.js b/e2e/draggable.js index 737e672..66d57d6 100644 --- a/e2e/draggable.js +++ b/e2e/draggable.js @@ -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"); @@ -70,16 +75,15 @@ 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); @@ -87,6 +91,7 @@ describe('Draggable with Pointer events', () => { }); it("disposes drag handlers properly", () => { + drag(); draggable.destroy(); draggable = null; @@ -94,6 +99,11 @@ describe('Draggable with Pointer events', () => { expect(handler).toHaveBeenCalledTimes(1); }); + + it("does not trigger drag before press", () => { + pointermove(el, 101, 201); + expect(handler).not.toHaveBeenCalled(); + }); }); describe("Release", () => { diff --git a/src/main.js b/src/main.js index 3044b26..f863225 100644 --- a/src/main.js +++ b/src/main.js @@ -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); @@ -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); } @@ -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);