Skip to content

Commit

Permalink
fix: don't trigger release when the element was not pressed with poin…
Browse files Browse the repository at this point in the history
…ter events
  • Loading branch information
danielkaradachki committed Jul 5, 2018
1 parent ad34a83 commit bd7ded8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 11 additions & 3 deletions e2e/draggable.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,30 @@ describe('Draggable with Pointer events', () => {
});

draggable.bindTo(el);
});

it("triggers release on pointerup", () => {
pointerdown(el, 100, 200);
pointermove(el, 101, 201);
pointerup(el, 101, 201);

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

it("triggers release on pointerup", () => {
expect(handler).toHaveBeenCalled();
it("does not trigger release if the element was not pressed", () => {
pointerup(el, 100, 200);
expect(handler).not.toHaveBeenCalled();
});

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

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

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

it("restores auto touch-action on pointerup", () => {
Expand All @@ -152,6 +159,7 @@ describe('Draggable with Pointer events', () => {
pointerup(el, 100, 200);
expect(el.style.touchAction).toEqual('pan-y');
});

});

describe("with mouseOnly set to true", () => {
Expand Down
7 changes: 6 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ export class Draggable {
this._pointerdown = (e) => {
if (e.isPrimary && e.button === 0) {
bind(this._element, "pointermove", this._pointermove);
bind(this._element, "pointerup", this._pointerup);

this._touchAction = e.target.style.touchAction;
e.target.style.touchAction = "none";
e.target.setPointerCapture(e.pointerId);

this._pressHandler(e);
}
};
Expand All @@ -117,8 +120,11 @@ export class Draggable {
this._pointerup = (e) => {
if (e.isPrimary) {
unbind(this._element, "pointermove", this._pointermove);
unbind(this._element, "pointerup", this._pointerup);

e.target.style.touchAction = this._touchAction;
e.target.releasePointerCapture(e.pointerId);

this._releaseHandler(e);
}
};
Expand All @@ -142,7 +148,6 @@ export class Draggable {

if (this._usePointers()) {
bind(element, "pointerdown", this._pointerdown);
bind(element, "pointerup", this._pointerup);
return;
}

Expand Down

0 comments on commit bd7ded8

Please sign in to comment.