Skip to content

Commit 2932f32

Browse files
authored
DataGrid - Focused cell moves to the end of the table after horizontal scrolling ( T1262288) (#28839)
1 parent c900475 commit 2932f32

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
@@ -1764,3 +1764,33 @@ test('DataGrid - Gray boxes appear when the push method is used to remove rows i
17641764
};
17651765
});
17661766
});
1767+
1768+
// T1262288
1769+
test('DataGrid - Focused cell moves to the end of the table after horizontal scrolling', async (t) => {
1770+
const dataGrid = new DataGrid('#container');
1771+
1772+
await t
1773+
.click(dataGrid.getDataCell(0, 0).element)
1774+
.pressKey('left');
1775+
1776+
await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();
1777+
1778+
await dataGrid.scrollBy({ x: 1000 });
1779+
await dataGrid.scrollBy({ x: -1000 });
1780+
1781+
await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();
1782+
}).before(async () => createWidget('dxDataGrid', {
1783+
dataSource: getData(1, 20).map((item, index) => ({ ...item, id: index })),
1784+
keyExpr: 'id',
1785+
columnWidth: 100,
1786+
showBorders: true,
1787+
focusedRowEnabled: true,
1788+
scrolling: {
1789+
columnRenderingMode: 'virtual',
1790+
mode: 'virtual',
1791+
showScrollbar: 'always',
1792+
},
1793+
paging: {
1794+
enabled: false,
1795+
},
1796+
}));

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
@@ -289,7 +289,7 @@ export class KeyboardNavigationController extends modules.ViewController {
289289
// @ts-expect-error
290290
const root = $(domAdapter.getRootNode($rowsView.get && $rowsView.get(0)));
291291
const $focusedElement = root.find(':focus');
292-
const isFocusedElementCorrect = !$focusedElement.length || $focusedElement.closest($rowsView).length;
292+
const isFocusedElementCorrect = this._isFocusedElementCorrect($focusedElement, $rowsView, e);
293293

294294
this.unsubscribeFromRowsViewFocusEvent();
295295
this.subscribeToRowsViewFocusEvent();
@@ -302,8 +302,25 @@ export class KeyboardNavigationController extends modules.ViewController {
302302
needUpdateFocus = this._isNeedFocus
303303
? !isAppend
304304
: this._isHiddenFocus && isFullUpdate && !e?.virtualColumnsScrolling;
305-
needUpdateFocus && this._updateFocus(true);
305+
if (needUpdateFocus) {
306+
this._updateFocus(true);
307+
}
308+
}
309+
}
310+
311+
private _isFocusedElementCorrect($focusedElement, $rowsView, e) {
312+
if ($focusedElement.length && !$focusedElement.closest($rowsView).length) {
313+
return false;
306314
}
315+
316+
if (!$focusedElement.length && e?.virtualColumnsScrolling) {
317+
const focusedColumnIndex = this._focusedCellPosition?.columnIndex ?? -1;
318+
const focusedColumnIndexWithoutOffset = focusedColumnIndex - this._getFocusedColumnIndexOffset(focusedColumnIndex);
319+
320+
return focusedColumnIndexWithoutOffset >= 0;
321+
}
322+
323+
return true;
307324
}
308325

309326
private initColumnHeadersViewHandler(): void {

0 commit comments

Comments
 (0)