Skip to content

Commit

Permalink
DataGrid - Focused cell moves to the end of the table after horizonta…
Browse files Browse the repository at this point in the history
…l scrolling ( T1262288) (DevExpress#28839)
  • Loading branch information
tongsonbarbs authored Jan 28, 2025
1 parent c900475 commit 2932f32
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
30 changes: 30 additions & 0 deletions e2e/testcafe-devextreme/tests/dataGrid/scrolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1764,3 +1764,33 @@ test('DataGrid - Gray boxes appear when the push method is used to remove rows i
};
});
});

// T1262288
test('DataGrid - Focused cell moves to the end of the table after horizontal scrolling', async (t) => {
const dataGrid = new DataGrid('#container');

await t
.click(dataGrid.getDataCell(0, 0).element)
.pressKey('left');

await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();

await dataGrid.scrollBy({ x: 1000 });
await dataGrid.scrollBy({ x: -1000 });

await t.expect(dataGrid.getDataCell(0, 0).isFocused).ok();
}).before(async () => createWidget('dxDataGrid', {
dataSource: getData(1, 20).map((item, index) => ({ ...item, id: index })),
keyExpr: 'id',
columnWidth: 100,
showBorders: true,
focusedRowEnabled: true,
scrolling: {
columnRenderingMode: 'virtual',
mode: 'virtual',
showScrollbar: 'always',
},
paging: {
enabled: false,
},
}));
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ export class KeyboardNavigationController extends modules.ViewController {
// @ts-expect-error
const root = $(domAdapter.getRootNode($rowsView.get && $rowsView.get(0)));
const $focusedElement = root.find(':focus');
const isFocusedElementCorrect = !$focusedElement.length || $focusedElement.closest($rowsView).length;
const isFocusedElementCorrect = this._isFocusedElementCorrect($focusedElement, $rowsView, e);

this.unsubscribeFromRowsViewFocusEvent();
this.subscribeToRowsViewFocusEvent();
Expand All @@ -302,8 +302,25 @@ export class KeyboardNavigationController extends modules.ViewController {
needUpdateFocus = this._isNeedFocus
? !isAppend
: this._isHiddenFocus && isFullUpdate && !e?.virtualColumnsScrolling;
needUpdateFocus && this._updateFocus(true);
if (needUpdateFocus) {
this._updateFocus(true);
}
}
}

private _isFocusedElementCorrect($focusedElement, $rowsView, e) {
if ($focusedElement.length && !$focusedElement.closest($rowsView).length) {
return false;
}

if (!$focusedElement.length && e?.virtualColumnsScrolling) {
const focusedColumnIndex = this._focusedCellPosition?.columnIndex ?? -1;
const focusedColumnIndexWithoutOffset = focusedColumnIndex - this._getFocusedColumnIndexOffset(focusedColumnIndex);

return focusedColumnIndexWithoutOffset >= 0;
}

return true;
}

private initColumnHeadersViewHandler(): void {
Expand Down

0 comments on commit 2932f32

Please sign in to comment.