From 9ac8579b0ae18e6b67471001567c8568370f30df Mon Sep 17 00:00:00 2001 From: Roman Semenov Date: Mon, 11 Sep 2023 06:48:34 +0400 Subject: [PATCH] DataGrid - Master-detail - It's not possible to focus all rows after rows are expanded and collapsed (T1187124) (#25543) --- .../m_keyboard_navigation.ts | 16 ++++---- .../keyboardNavigation.functional.ts | 41 ++++++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts b/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts index efe24e0baee8..fc452e406eb5 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts @@ -1733,17 +1733,19 @@ export class KeyboardNavigationController extends modules.ViewController { return this._isCellValid($cell); } - _isLastRow(rowIndex) { - const dataController = this._dataController as any; - const visibleItems = dataController - .items() - .filter((item) => item.visible !== false); + private _isLastRow(rowIndex: number): boolean { + const dataController = this._dataController; if (this._isVirtualRowRender()) { - return rowIndex >= dataController.getMaxRowIndex(); + return rowIndex >= (dataController as any).getMaxRowIndex(); } - return rowIndex === visibleItems.length - 1; + const lastVisibleIndex = Math.max( + ...dataController.items() + .map((item, index) => (item.visible !== false ? index : -1)), + ); + + return rowIndex === lastVisibleIndex; } _isFirstValidCell(cellPosition) { diff --git a/packages/devextreme/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts b/packages/devextreme/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts index 947664867981..5bab5d0827c4 100644 --- a/packages/devextreme/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts +++ b/packages/devextreme/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts @@ -4334,7 +4334,7 @@ test('Focus first cell with dropDownButton (via tab key) -> open dropDownButton }); }, }, 'field2', 'field3'], -}, undefined, { disableFxAnimation: true })); +})); // T1185341 test('Focus second cell (via click) -> tab navigation when focusedRowEnabled is true', async (t) => { @@ -4373,4 +4373,41 @@ test('Focus second cell (via click) -> tab navigation when focusedRowEnabled is }); }, }, 'field2', 'field3'], -}, undefined, { disableFxAnimation: true })); +})); + +// T1187124 +test('Keyboard navigation should work after opening-closing master-detal', async (t) => { + const dataGrid = new DataGrid('#container'); + + await t.click(dataGrid.getDataRow(0).getCommandCell(0).element); // open master detail + await t.click(dataGrid.getDataRow(0).getCommandCell(0).element); // close master detail + + await t + .click(dataGrid.getHeaders().getHeaderRow(0).getHeaderCell(1).element) + .pressKey('tab') + .pressKey('tab') + .expect(dataGrid.getDataCell(0, 1).isFocused) + .ok(); + + await t + .pressKey('down') + .expect(dataGrid.getDataCell(1, 1).isFocused).ok(); + + await t + .pressKey('down') + .expect(dataGrid.getDataCell(2, 1).isFocused).ok(); + await t + .pressKey('down') + .expect(dataGrid.getDataCell(3, 1).isFocused).ok(); +}).before(async () => createWidget('dxDataGrid', { + dataSource: [ + { id: 1 }, + { id: 2 }, + { id: 3 }, + { id: 4 }, + ], + keyExpr: 'id', + masterDetail: { + enabled: true, + }, +}));