SitePen / dgrid

A lightweight, mobile-ready, data-driven, modular grid widget designed for use with dstore
http://dgrid.io/
Other
628 stars 295 forks source link

DnD eating onMouseDown events breaks dgrid selection #1401

Closed dylans closed 4 years ago

dylans commented 7 years ago

As reported by @jjrv in https://github.com/dojo/dojo/issues/278:

I have a dgrid like OnDemandGrid.createSubclass([ Keyboard, ColumnResizer ]).createSubclass([ Tree, Editor, DnD ])

With DnD enabled, clicking on a cell doesn't move the "keyboard focus" there. Meaning arrow keys jump back to the previous cell selected using the keyboard or by clicking on a form element.

I tracked the issue to this repo, dnd/Selector.js here and here.

It seems the mousedown event doesn't reach some relevant handler in dgrid. The stopPropagation in this repo was apparently intended to stop text selection, but dgrid or its mixins already handle that.

I don't know of any nice way to handle this special case with dgrid without possibly breaking something else. I simply used dojo/aspect to redirect the event's stopPropagation and preventDefault methods to blank functions before reaching onMouseDown in Selector.js. That fixes the problem for my case.

For the record, here's the (TypeScript) code for patching the event:

import * as Source from 'dojo/dnd/Source';

function nop() {}

aspect.before((Source as any).superclass, 'onMouseDown', (e: MouseEvent) => {
    e.stopPropagation = nop;
    e.preventDefault = nop;
    return([ e ]);
});
msssk commented 5 years ago

This should be fixed in #1445

msssk commented 4 years ago

Closing this since #1445 has ben merged.