Skip to content

Commit 9c39de5

Browse files
committed
fix(interactions): ignore secondary-button cell range drags
1 parent 4559db9 commit 9c39de5

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

cypress/e2e/example-plugin-hybridselectionmodel.cy.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,21 @@ describe('Example - Context Menu Plugin & Hybrid Selection Mode', () => {
3232
cy.get('#myGrid .slick-cell.selected').should('have.length', 4);
3333
});
3434

35+
it('should preserve cell selection when dragging with the secondary mouse button', () => {
36+
cy.get('#myGrid .slick-cell.selected').should('have.length', 4);
37+
38+
cy.get('#myGrid .slick-row[data-row="1"] .slick-cell.l1.r1').trigger('mousedown', {
39+
button: 2,
40+
which: 3,
41+
force: true,
42+
});
43+
cy.get('#myGrid .slick-row[data-row="3"] .slick-cell.l3.r3')
44+
.trigger('mousemove', 'bottomRight')
45+
.trigger('mouseup', 'bottomRight', { button: 2, which: 3, force: true });
46+
47+
cy.get('#myGrid .slick-cell.selected').should('have.length', 4);
48+
});
49+
3550
it('should be able to expand the cell selections further to the right', () => {
3651
cy.get('#myGrid .slick-cell.selected').should('have.length', 4);
3752
cy.get('#myGrid .slick-row[data-row="2"] .slick-cell.l2.r2')

src/slick.interactions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ export function Draggable(options: DraggableOption) {
8484
}
8585

8686
function userPressed(event: MouseEvent | TouchEvent | KeyboardEvent) {
87+
// Dragging is a primary-button action; allow secondary clicks to continue
88+
// to context-menu handling without starting a drag.
89+
// Keep synthetic mousedown CustomEvents compatible (they have no `button`).
90+
if (event.type === 'mousedown' && 'button' in event && (event as MouseEvent).button !== 0) {
91+
return;
92+
}
93+
8794
if (!preventDrag(event)) {
8895
element = event.target as HTMLElement;
8996
const targetEvent: MouseEvent | Touch = (event as TouchEvent)?.touches?.[0] ?? event;

0 commit comments

Comments
 (0)