From 35f15e92dcd49db8a228eb1d638494f82a06cb78 Mon Sep 17 00:00:00 2001 From: Roman Semenov Date: Wed, 4 Oct 2023 11:49:20 +0400 Subject: [PATCH] DataGrid - Opening an editor with the Enter key is inconsistent when scrolling is enabled (T1190668) (#25719) --- .../m_keyboard_navigation.ts | 4 +- .../startEditing.functional.ts | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 testing/testcafe/tests/dataGrid/keyboardNavigation/startEditing.functional.ts 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 9300f0ea4f2b..6b3e2f805ee5 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 @@ -2689,8 +2689,10 @@ export const keyboardNavigationModule: import('../m_types').Module = { getFocusedCellInRow(rowIndex) { const keyboardNavigationController = this.getController('keyboardNavigation'); let $cell = this.callBase(rowIndex); + const rowIndexOffset = this._dataController.getRowIndexOffset(); + const focusedRowIndex = keyboardNavigationController._focusedCellPosition.rowIndex - rowIndexOffset; - if (keyboardNavigationController.isKeyboardEnabled() && keyboardNavigationController._focusedCellPosition.rowIndex === rowIndex) { + if (keyboardNavigationController.isKeyboardEnabled() && focusedRowIndex === rowIndex) { const $focusedCell = keyboardNavigationController._getFocusedCell(); if (isElementDefined($focusedCell) && !$focusedCell.hasClass(COMMAND_EDIT_CLASS)) { $cell = $focusedCell; diff --git a/testing/testcafe/tests/dataGrid/keyboardNavigation/startEditing.functional.ts b/testing/testcafe/tests/dataGrid/keyboardNavigation/startEditing.functional.ts new file mode 100644 index 000000000000..d6a27ac35f3d --- /dev/null +++ b/testing/testcafe/tests/dataGrid/keyboardNavigation/startEditing.functional.ts @@ -0,0 +1,37 @@ +import url from '../../../helpers/getPageUrl'; +import createWidget from '../../../helpers/createWidget'; +import DataGrid from '../../../model/dataGrid'; + +fixture`Keyboard Navigation - editOnKeyPress` + .page(url(__dirname, '../../container.html')); + +const DATA_GRID_SELECTOR = '#container'; + +test('Editing should start by pressing enter after scrolling content with scrolling.mode=virtual', async (t) => { + const dataGrid = new DataGrid(DATA_GRID_SELECTOR); + + await dataGrid.scrollBy({ y: 10000 }); + + await t.click(dataGrid.getDataCell(49, 1).element); + await t.pressKey('enter'); + + await t.expect(dataGrid.getDataCell(49, 1).getEditor().element.focused).ok(); +}).before(async () => { + await createWidget('dxDataGrid', { + dataSource: [...new Array(50)].map((_, i) => ({ + data1: i * 2, + data2: i * 2 + 1, + })), + columns: [ + 'data1', + 'data2', + ], + editing: { + allowUpdating: true, + }, + scrolling: { + mode: 'virtual', + }, + height: 300, + }); +});