Skip to content

Commit ce9a462

Browse files
fix: stop grid column reordering on contextmenu event (#5430) (#5431)
Co-authored-by: Tomi Virkki <tomivirkki@users.noreply.github.com>
1 parent 3ea0e98 commit ce9a462

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

packages/grid/src/vaadin-grid-column-reordering-mixin.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright (c) 2016 - 2022 Vaadin Ltd.
44
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
55
*/
6+
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
67
import { addListener } from '@vaadin/component-base/src/gestures.js';
78
import { updateColumnOrders } from './vaadin-grid-helpers.js';
89

@@ -51,6 +52,14 @@ export const ColumnReorderingMixin = (superClass) =>
5152
_onContextMenu(e) {
5253
if (this.hasAttribute('reordering')) {
5354
e.preventDefault();
55+
56+
// A contextmenu event is fired on mobile Chrome on long-press
57+
// (which should start reordering). Don't end the reorder on touch devices.
58+
if (!isTouch) {
59+
// Context menu cancels the track gesture on desktop without firing an end event.
60+
// End the reorder manually.
61+
this._onTrackEnd();
62+
}
5463
}
5564
}
5665

packages/grid/test/column-reordering.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import sinon from 'sinon';
44
import '@vaadin/polymer-legacy-adapter/template-renderer.js';
55
import '../vaadin-grid.js';
66
import '../vaadin-grid-column-group.js';
7+
import { isTouch } from '@vaadin/component-base/src/browser-utils.js';
78
import {
89
dragAndDropOver,
910
dragOver,
@@ -177,6 +178,16 @@ describe('reordering simple grid', () => {
177178
expect(e.defaultPrevented).to.be.false;
178179
});
179180

181+
it('should cancel reorder on contextmenu on desktop', () => {
182+
dragStart(headerContent[0]);
183+
184+
const e = new CustomEvent('contextmenu', { cancelable: true, bubbles: true });
185+
headerContent[0].dispatchEvent(e);
186+
187+
const cell = getCellByCellContent(headerContent[0]);
188+
expect(cell.getAttribute('reorder-status')).to.equal(!isTouch ? '' : 'dragging');
189+
});
190+
180191
describe('touch gesture delay', () => {
181192
let clock;
182193

0 commit comments

Comments
 (0)