Skip to content

Commit bd7ded8

Browse files
fix: don't trigger release when the element was not pressed with pointer events
1 parent ad34a83 commit bd7ded8

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

e2e/draggable.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,23 +121,30 @@ describe('Draggable with Pointer events', () => {
121121
});
122122

123123
draggable.bindTo(el);
124+
});
124125

126+
it("triggers release on pointerup", () => {
125127
pointerdown(el, 100, 200);
126128
pointermove(el, 101, 201);
127129
pointerup(el, 101, 201);
130+
131+
expect(handler).toHaveBeenCalledTimes(1);
128132
});
129133

130-
it("triggers release on pointerup", () => {
131-
expect(handler).toHaveBeenCalled();
134+
it("does not trigger release if the element was not pressed", () => {
135+
pointerup(el, 100, 200);
136+
expect(handler).not.toHaveBeenCalled();
132137
});
133138

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

143+
pointerdown(el, 100, 200);
144+
pointermove(el, 101, 201);
138145
pointerup(el, 101, 201);
139146

140-
expect(handler).toHaveBeenCalledTimes(1);
147+
expect(handler).not.toHaveBeenCalled();
141148
});
142149

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

157165
describe("with mouseOnly set to true", () => {

src/main.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,12 @@ export class Draggable {
101101
this._pointerdown = (e) => {
102102
if (e.isPrimary && e.button === 0) {
103103
bind(this._element, "pointermove", this._pointermove);
104+
bind(this._element, "pointerup", this._pointerup);
105+
104106
this._touchAction = e.target.style.touchAction;
105107
e.target.style.touchAction = "none";
106108
e.target.setPointerCapture(e.pointerId);
109+
107110
this._pressHandler(e);
108111
}
109112
};
@@ -117,8 +120,11 @@ export class Draggable {
117120
this._pointerup = (e) => {
118121
if (e.isPrimary) {
119122
unbind(this._element, "pointermove", this._pointermove);
123+
unbind(this._element, "pointerup", this._pointerup);
124+
120125
e.target.style.touchAction = this._touchAction;
121126
e.target.releasePointerCapture(e.pointerId);
127+
122128
this._releaseHandler(e);
123129
}
124130
};
@@ -142,7 +148,6 @@ export class Draggable {
142148

143149
if (this._usePointers()) {
144150
bind(element, "pointerdown", this._pointerdown);
145-
bind(element, "pointerup", this._pointerup);
146151
return;
147152
}
148153

0 commit comments

Comments
 (0)