Skip to content

Commit 1f8faf4

Browse files
mssskedhager
authored andcommitted
Fix Keyboard and DnD incompatibility (#1067) (#1445)
`dgrid/extensions/DnD` uses `dojo/dnd/Source` which registers an event handler using `on(node, touch.press)`. `touch.press` evaluates to `'pointerdown'` in browsers that support pointer events, and when the `'pointerdown'` listener is registered the `'mousedown'` listener is never called. This change causes Keyboard to use `touch.press` when DnD is being used. It also exposes a new configuration property, `mouseDownEventType`, which enables developers to further customize this behavior.
1 parent f3f61a5 commit 1f8faf4

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

Keyboard.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ define([
3737
// of the instance) for key events within the grid's header row.
3838
headerKeyMap: null,
3939

40+
// mouseDownEventType: dojo/on compatible event type
41+
// Event type to use for Keyboard's mouse down listener that sets focus.
42+
mouseDownEventType: 'mousedown',
43+
4044
postMixInProperties: function () {
4145
this.inherited(arguments);
4246

@@ -141,7 +145,7 @@ define([
141145
);
142146
}
143147

144-
grid._listeners.push(on(areaNode, 'mousedown', function (event) {
148+
grid._listeners.push(on(areaNode, grid.mouseDownEventType, function (event) {
145149
if (!handledEvent(event)) {
146150
grid._focusOnNode(event.target, isHeader, event);
147151
}

doc/components/mixins/Keyboard.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Property | Description
3434
`pageSkip` | Number indicating how many rows to navigate when page up or page down is pressed. Defaults to `10`.
3535
`keyMap` | Object hash mapping key codes to callbacks to be executed when the respective keys are pressed within the body of the grid. This is typically augmented by calling `addKeyHandler`, but it can also be completely overridden by passing an object hash to the constructor (or otherwise creating one before `Keyboard#postMixInProperties` executes). The default `keyMap` is exposed via `Keyboard.defaultKeyMap`.
3636
`headerKeyMap` | Object hash mapping key codes to callbacks to be executed when the respective keys are pressed within the header of the grid. This is typically augmented by calling `addKeyHandler`, but it can also be completely overridden by passing an object hash to the constructor (or otherwise creating one before `Keyboard#postMixInProperties` executes). The default `headerKeyMap` is exposed via `Keyboard.defaultHeaderKeyMap`.
37+
`mouseDownEventType` | `dojo/on` compatible event type. Defaults to `'mousedown'`. Can be overridden to use a different event type to register the mouse down event handler that sets focus. Overridden by `dgrid/extensions/DnD` to `touch.press` (from `dojo/touch`) for compatibility with `dojo/dnd/Source`, which is used by `dgrid/extensions/DnD`.
3738

3839
### Method Summary
3940

extensions/DnD.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ define([
44
'dojo/_base/array',
55
'dojo/aspect',
66
'dojo/dom-class',
7-
'dojo/on',
87
'dojo/topic',
8+
'dojo/touch',
99
'dojo/has',
1010
'dojo/when',
1111
'dojo/dnd/Source',
1212
'dojo/dnd/Manager',
1313
'dojo/_base/NodeList',
1414
'../Selection',
1515
'dojo/has!touch?../util/touch'
16-
], function (declare, lang, arrayUtil, aspect, domClass, on, topic, has, when, DnDSource,
16+
], function (declare, lang, arrayUtil, aspect, domClass, topic, touch, has, when, DnDSource,
1717
DnDManager, NodeList, Selection, touchUtil) {
1818
// Requirements
1919
// * requires a store (sounds obvious, but not all Lists/Grids have stores...)
@@ -260,6 +260,15 @@ define([
260260
this.inherited(arguments);
261261
// ensure dndParams is initialized
262262
this.dndParams = lang.mixin({ accept: [this.dndSourceType] }, this.dndParams);
263+
264+
// The DnD extension adds a touch.press listener (via dojo/dnd/Source). In browsers
265+
// that support pointer events the presence of this listener prevents dgrid/Keyboard's
266+
// 'mousedown' listener from being called. To ensure dgrid/Keyboard works in conjunction
267+
// with DnD the mouse down event type for dgrid/Keyboard is changed to touch.press.
268+
// Note: this is set in postMixInProperties to ensure it overrides the value in Keyboard
269+
// regardless of which module is mixed in first. This means that if you want to override
270+
// the value set in DnD you need to do so in the postMixInProperties lifecycle method.
271+
this.mouseDownEventType = touch.press;
263272
},
264273

265274
postCreate: function () {

0 commit comments

Comments
 (0)