Skip to content

Commit 2a59c94

Browse files
authored
DataGrid - Focused cell moves to the end of the table after horizontal scrolling (T1262288) (#28840)
1 parent dab6ba3 commit 2a59c94

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

e2e/testcafe-devextreme/tests/dataGrid/scrolling.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,3 +1748,33 @@ test('DataGrid - Gray boxes appear when the push method is used to remove rows i
17481748
};
17491749
});
17501750
});
1751+
1752+
// T1262288
1753+
test('DataGrid - Focused cell moves to the end of the table after horizontal scrolling', async (t) => {
1754+
const dataGrid = new DataGrid('#container');
1755+
1756+
await t
1757+
.click(dataGrid.getDataCell(0, 0).element)
1758+
.pressKey('left');
1759+
1760+
await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();
1761+
1762+
await dataGrid.scrollBy({ x: 1000 });
1763+
await dataGrid.scrollBy({ x: -1000 });
1764+
1765+
await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();
1766+
}).before(async () => createWidget('dxDataGrid', {
1767+
dataSource: getData(1, 20).map((item, index) => ({ ...item, id: index })),
1768+
keyExpr: 'id',
1769+
columnWidth: 100,
1770+
showBorders: true,
1771+
focusedRowEnabled: true,
1772+
scrolling: {
1773+
columnRenderingMode: 'virtual',
1774+
mode: 'virtual',
1775+
showScrollbar: 'always',
1776+
},
1777+
paging: {
1778+
enabled: false,
1779+
},
1780+
}));

packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ export class KeyboardNavigationController extends modules.ViewController {
275275
// @ts-expect-error
276276
const root = $(domAdapter.getRootNode($rowsView.get && $rowsView.get(0)));
277277
const $focusedElement = root.find(':focus');
278-
const isFocusedElementCorrect = !$focusedElement.length || $focusedElement.closest($rowsView).length;
278+
const isFocusedElementCorrect = this._isFocusedElementCorrect($focusedElement, $rowsView, e);
279279

280280
this.unsubscribeFromRowsViewFocusEvent();
281281
this.subscribeToRowsViewFocusEvent();
@@ -288,8 +288,25 @@ export class KeyboardNavigationController extends modules.ViewController {
288288
needUpdateFocus = this._isNeedFocus
289289
? !isAppend
290290
: this._isHiddenFocus && isFullUpdate && !e?.virtualColumnsScrolling;
291-
needUpdateFocus && this._updateFocus(true);
291+
if (needUpdateFocus) {
292+
this._updateFocus(true);
293+
}
294+
}
295+
}
296+
297+
private _isFocusedElementCorrect($focusedElement, $rowsView, e) {
298+
if ($focusedElement.length && !$focusedElement.closest($rowsView).length) {
299+
return false;
292300
}
301+
302+
if (!$focusedElement.length && e?.virtualColumnsScrolling) {
303+
const focusedColumnIndex = this._focusedCellPosition?.columnIndex ?? -1;
304+
const focusedColumnIndexWithoutOffset = focusedColumnIndex - this._getFocusedColumnIndexOffset(focusedColumnIndex);
305+
306+
return focusedColumnIndexWithoutOffset >= 0;
307+
}
308+
309+
return true;
293310
}
294311

295312
private initViewHandlers(): void {

0 commit comments

Comments
 (0)