Skip to content

Commit a2e91cb

Browse files
committed
refactor: Disable contextmenu during resize & drag
1 parent 6943f09 commit a2e91cb

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/components/common/controllers/drag.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ type DragControllerConfiguration = {
8686
cancel?: DragCancelCallback;
8787
};
8888

89-
const additionalEvents = ['pointermove', 'lostpointercapture'] as const;
89+
const additionalEvents = [
90+
'pointermove',
91+
'lostpointercapture',
92+
'contextmenu',
93+
] as const;
9094

9195
class DragController implements ReactiveController {
9296
private _host: ReactiveControllerHost & LitElement;
@@ -193,15 +197,13 @@ class DragController implements ReactiveController {
193197
this._host.addEventListener('dragstart', this);
194198
this._host.addEventListener('touchstart', this, { passive: false });
195199
this._host.addEventListener('pointerdown', this);
196-
globalThis.addEventListener('contextmenu', this._handleContextMenu);
197200
}
198201

199202
/** @internal */
200203
public hostDisconnected(): void {
201204
this._host.removeEventListener('dragstart', this);
202205
this._host.removeEventListener('touchstart', this);
203206
this._host.removeEventListener('pointerdown', this);
204-
globalThis.removeEventListener('contextmenu', this._handleContextMenu);
205207
this._setDragCancelListener(false);
206208
this._removeGhost();
207209
}
@@ -215,6 +217,8 @@ class DragController implements ReactiveController {
215217
switch (event.type) {
216218
case 'touchstart':
217219
case 'dragstart':
220+
// Prevent contextmenu default behavior during drag
221+
case 'contextmenu':
218222
event.preventDefault();
219223
break;
220224
case 'keydown':
@@ -286,11 +290,6 @@ class DragController implements ReactiveController {
286290
}
287291
}
288292

289-
private _handleContextMenu(event: MouseEvent): void {
290-
// Prevents the default context menu while dragging
291-
event.preventDefault();
292-
}
293-
294293
// #endregion
295294

296295
private _setDragCancelListener(enabled = true): void {

src/components/resize-container/resize-controller.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import { findElementFromEventPath } from '../common/util.js';
44
import { createDefaultGhostElement, getDefaultLayer } from './default-ghost.js';
55
import type { ResizeControllerConfiguration, ResizeState } from './types.js';
66

7-
const additionalEvents = ['pointermove', 'lostpointercapture'] as const;
7+
const additionalEvents = [
8+
'pointermove',
9+
'lostpointercapture',
10+
'contextmenu',
11+
] as const;
812

913
type State = {
1014
initial: DOMRect;
@@ -110,6 +114,8 @@ class ResizeController implements ReactiveController {
110114

111115
switch (event.type) {
112116
case 'touchstart':
117+
// Prevent contextmenu default behavior during resize
118+
case 'contextmenu':
113119
event.preventDefault();
114120
break;
115121
case 'keydown':

0 commit comments

Comments
 (0)