Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1307def

Browse files
committed
using passive:true for mousemove events
* our app was showing errors calling e.preventDefault() because move events were marked as passive (which are more performant for smooth scrolling) so explicitly set it passive and skip the call. * verified the old issue of sweep selecting text field content isn't an issue anymore
1 parent a691bb3 commit 1307def

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

doc/CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ Change log
114114
* fix: [#2576](https://github.com/gridstack/gridstack.js/issues/2576) column('none') now ignores layouts
115115
* fix: [#2560](https://github.com/gridstack/gridstack.js/issues/2560) nested grid fix (enter can call leave which can call enter again) - Thank you [v1talii-dev](https://github.com/v1talii-dev)
116116
* fix: [#2596](https://github.com/gridstack/gridstack.js/pull/2596) prevent SSR crash
117+
* fix: [#2610](https://github.com/gridstack/gridstack.js/pull/2610) using passive:true for mousemove events
117118
* demo: nested.htm now has nested create and drag&drop example - Thank you [fredericrous](https://github.com/fredericrous)
118119

119120
## 10.0.1 (2023-12-10)

src/dd-draggable.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
158158
delete DDManager.dragElement;
159159
delete DDManager.dropElement;
160160
// document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
161-
document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
161+
document.addEventListener('mousemove', this._mouseMove, { capture: true, passive: true}); // true=capture, not bubble
162162
document.addEventListener('mouseup', this._mouseUp, true);
163163
if (isTouch) {
164164
this.dragEl.addEventListener('touchmove', touchmove);
@@ -226,7 +226,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
226226
}
227227
this.triggerEvent('dragstart', ev);
228228
}
229-
e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around
229+
// e.preventDefault(); // passive = true. OLD: was needed otherwise we get text sweep text selection as we drag around
230230
return true;
231231
}
232232

src/dd-resizable-handle.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export class DDResizableHandle {
7474
/** @internal called on mouse down on us: capture move on the entire document (mouse might not stay on us) until we release the mouse */
7575
protected _mouseDown(e: MouseEvent): void {
7676
this.mouseDownEvent = e;
77-
document.addEventListener('mousemove', this._mouseMove, true); // capture, not bubble
77+
document.addEventListener('mousemove', this._mouseMove, { capture: true, passive: true}); // capture, not bubble
7878
document.addEventListener('mouseup', this._mouseUp, true);
7979
if (isTouch) {
8080
this.el.addEventListener('touchmove', touchmove);
@@ -96,7 +96,7 @@ export class DDResizableHandle {
9696
this._triggerEvent('move', e);
9797
}
9898
e.stopPropagation();
99-
e.preventDefault();
99+
// e.preventDefault(); passive = true
100100
}
101101

102102
/** @internal */

0 commit comments

Comments
 (0)