From f0a734a8519689221ca608a8f8599a6f483b1d37 Mon Sep 17 00:00:00 2001 From: Roman Semenov Date: Wed, 13 Sep 2023 09:30:23 +0400 Subject: [PATCH] DataGrid - Master-detail - It's not possible to focus all rows after rows are expanded and collapsed (T1187124) (#25569) --- .../m_keyboard_navigation.ts | 16 ++++---- .../keyboardNavigation.functional.ts | 41 ++++++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts b/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts index 3429a89d291d..9300f0ea4f2b 100644 --- a/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts +++ b/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts @@ -1721,17 +1721,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/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts b/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts index fa6291078a7c..4f7da70508cc 100644 --- a/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts +++ b/testing/testcafe/tests/dataGrid/keyboardNavigation/keyboardNavigation.functional.ts @@ -4244,7 +4244,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) => { @@ -4283,4 +4283,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, + }, +}));