Skip to content

Commit 9c4c7bd

Browse files
authored
DataGrid: Fix double calling of the onKeyDown event for headers and group panel (DevExpress#29845)
Co-authored-by: Alyar <>
1 parent 37a16db commit 9c4c7bd

File tree

3 files changed

+81
-5
lines changed

3 files changed

+81
-5
lines changed

e2e/testcafe-devextreme/tests/dataGrid/common/keyboardNavigation/keyboardNavigation.functional.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const getOrderOfEventCalls = ClientFunction(
1515
() => (window as any).focusedEventsTestData.map((data) => data.type),
1616
);
1717

18+
const getOnKeyDownCallCount = ClientFunction(() => (window as any).onKeyDownCallCount);
19+
1820
fixture.disablePageReloads`Keyboard Navigation - common`
1921
.page(url(__dirname, '../../../container.html'));
2022

@@ -5101,3 +5103,73 @@ test('Focus events should be called when pressing the Ctrl + End key', async (t)
51015103
delete (window as any).focusedEventsTestData;
51025104
})();
51035105
});
5106+
5107+
test('DataGrid - The onKeyDown event should be called once for group panel', async (t) => {
5108+
// arrange
5109+
const dataGrid = new DataGrid('#container');
5110+
const firstGroupedColumn = dataGrid.getGroupPanel().getHeader(0);
5111+
5112+
await t.click(firstGroupedColumn.element);
5113+
5114+
// act
5115+
await t.pressKey('tab');
5116+
5117+
// assert
5118+
await t.expect(getOnKeyDownCallCount()).eql(1);
5119+
}).before(async () => {
5120+
await ClientFunction(() => {
5121+
(window as any).onKeyDownCallCount = 0;
5122+
})();
5123+
5124+
await createWidget('dxDataGrid', {
5125+
dataSource: getData(5, 5),
5126+
showBorders: true,
5127+
onKeyDown() {
5128+
(window as any).onKeyDownCallCount += 1;
5129+
},
5130+
groupPanel: {
5131+
visible: true,
5132+
},
5133+
columns: [
5134+
{ dataField: 'field_0', groupIndex: 0 },
5135+
{ dataField: 'field_1', groupIndex: 1 },
5136+
'field_2',
5137+
'field_3',
5138+
'field_4',
5139+
],
5140+
});
5141+
}).after(async () => {
5142+
await ClientFunction(() => {
5143+
delete (window as any).onKeyDownCallCount;
5144+
})();
5145+
});
5146+
5147+
test('DataGrid - The onKeyDown event should be called once for headers', async (t) => {
5148+
// arrange
5149+
const dataGrid = new DataGrid('#container');
5150+
const firstHeader = dataGrid.getHeaders().getHeaderRow(0).getHeaderCell(0);
5151+
5152+
await t.click(firstHeader.element);
5153+
5154+
// act
5155+
await t.pressKey('tab');
5156+
5157+
// assert
5158+
await t.expect(getOnKeyDownCallCount()).eql(1);
5159+
}).before(async () => {
5160+
await ClientFunction(() => {
5161+
(window as any).onKeyDownCallCount = 0;
5162+
})();
5163+
5164+
await createWidget('dxDataGrid', {
5165+
dataSource: getData(5, 5),
5166+
showBorders: true,
5167+
onKeyDown() {
5168+
(window as any).onKeyDownCallCount += 1;
5169+
},
5170+
});
5171+
}).after(async () => {
5172+
await ClientFunction(() => {
5173+
delete (window as any).onKeyDownCallCount;
5174+
})();
5175+
});
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
import * as accessibility from '@js/ui/shared/accessibility';
22

33
export const registerKeyboardAction = function (viewName, instance, $element, selector, action) {
4+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
5+
let executeKeyDown = (args) => {};
46
const keyboardController = instance.getController('keyboardNavigation');
57
if (instance.option('useLegacyKeyboardNavigation') || (keyboardController && !keyboardController.isKeyboardEnabled())) {
68
return;
79
}
810

9-
const executeKeyDown = (args) => {
10-
instance.executeAction('onKeyDown', args);
11-
};
11+
if (viewName === 'filterPanel') {
12+
executeKeyDown = (args) => {
13+
instance.executeAction('onKeyDown', args);
14+
};
1215

13-
instance.createAction('onKeyDown');
16+
instance.createAction('onKeyDown');
17+
}
1418

1519
accessibility.registerKeyboardAction(viewName, instance, $element, selector, action, executeKeyDown);
1620
};

packages/devextreme/testing/tests/DevExpress.ui.widgets.dataGrid/keyboardNavigation.accessibility.tests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ QUnit.module('Keyboard navigation accessibility', {
7777

7878
setupDataGridModules(this,
7979
['data', 'columns', 'columnHeaders', 'sorting', 'columnFixing', 'grouping', 'groupPanel', 'headerPanel', 'pager', 'headerFilter', 'filterSync', 'filterPanel', 'filterRow',
80-
'rows', 'editorFactory', 'gridView', 'editing', 'editingRowBased', 'editingFormBased', 'editingCellBased', 'selection', 'focus', 'keyboardNavigation', 'validating', 'masterDetail'],
80+
'rows', 'editorFactory', 'gridView', 'editing', 'editingRowBased', 'editingFormBased', 'editingCellBased', 'selection', 'focus', 'groupPanelKeyboardNavigation', 'headersKeyboardNavigation', 'keyboardNavigation', 'validating', 'masterDetail'],
8181
{ initViews: true }
8282
);
8383
},

0 commit comments

Comments
 (0)