Skip to content

Commit d2cea2e

Browse files
authored
DataGrid: Fix quick navigation when adaptive is enabled (#30192)
Co-authored-by: Alyar <>
1 parent 88d7dca commit d2cea2e

File tree

5 files changed

+73
-1
lines changed

5 files changed

+73
-1
lines changed
Loading
Loading

e2e/testcafe-devextreme/tests/dataGrid/common/keyboardNavigation/keyboardNavigation.visual.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,69 @@ test('Navigate to first cell in the row that contains focus when virtual columns
262262
},
263263
}));
264264

265+
test('Navigate to last cell in the row that contains focus when adaptivity is enabled', async (t) => {
266+
// arrange
267+
const dataGrid = new DataGrid('#container');
268+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
269+
270+
// act
271+
await t
272+
.click(dataGrid.getDataCell(0, 0).element)
273+
.pressKey('end');
274+
275+
await takeScreenshot('navigate_to_last_cell_in_row_that_contains_focus_when_adaptivity_is_enabled', dataGrid.element);
276+
277+
// assert
278+
await t
279+
.expect(compareResults.isValid())
280+
.ok(compareResults.errorMessages());
281+
}).before(async () => createWidget('dxDataGrid', {
282+
dataSource: getData(20, 50),
283+
columnWidth: 100,
284+
height: 500,
285+
width: 800,
286+
showBorders: true,
287+
customizeColumns(columns) {
288+
columns[columns.length - 1].hidingPriority = 0;
289+
columns.splice(columns.length - 2, 0, { type: 'adaptive', width: 100 });
290+
},
291+
}));
292+
293+
test('Navigate to first cell in the row that contains focus when adaptivity is enabled', async (t) => {
294+
// arrange
295+
const dataGrid = new DataGrid('#container');
296+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
297+
298+
await dataGrid.scrollTo(t, { x: 4200 });
299+
300+
// assert
301+
await t
302+
.expect(dataGrid.getScrollLeft())
303+
.eql(4200);
304+
305+
// act
306+
await t
307+
.click(dataGrid.getDataCell(0, 50).element)
308+
.pressKey('home');
309+
310+
await takeScreenshot('navigate_to_first_cell_in_row_that_contains_focus_when_adaptivity_is_enabled', dataGrid.element);
311+
312+
// assert
313+
await t
314+
.expect(compareResults.isValid())
315+
.ok(compareResults.errorMessages());
316+
}).before(async () => createWidget('dxDataGrid', {
317+
dataSource: getData(20, 50),
318+
columnWidth: 100,
319+
height: 500,
320+
width: 800,
321+
showBorders: true,
322+
customizeColumns(columns) {
323+
columns[0].hidingPriority = 0;
324+
columns.push({ type: 'adaptive', width: 100 });
325+
},
326+
}));
327+
265328
// Quick navigation through grid rows via Ctrl+Home and Ctrl+End keys
266329
test('Focus the last cell in the last row when pressing the Ctrl+End key', async (t) => {
267330
// arrange

packages/devextreme/js/__internal/grids/grid_core/adaptivity/m_adaptivity.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,10 @@ const keyboardNavigation = (
851851
}
852852
}
853853

854+
protected isFocusableColumn(column: Column): boolean {
855+
return super.isFocusableColumn(column) && column.visibleWidth !== HIDDEN_COLUMNS_WIDTH;
856+
}
857+
854858
public _isCellElement($cell) {
855859
return super._isCellElement($cell) || $cell.hasClass(ADAPTIVE_ITEM_TEXT_CLASS);
856860
}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type { EditingController } from '@ts/grids/grid_core/editing/m_editing';
3131
import type { RowsView } from '@ts/grids/grid_core/views/m_rows_view';
3232
import { memoize } from '@ts/utils/memoize';
3333

34+
import type { Column } from '../columns_controller/m_columns_controller';
3435
import {
3536
EDIT_FORM_CLASS,
3637
EDIT_MODE_BATCH,
@@ -1243,7 +1244,7 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
12431244

12441245
private getFirstOrLastColumnIndex(needFirstColumnIndex: boolean): number {
12451246
const allVisibleColumns: any[] = this._columnsController.getVisibleColumns(null, true);
1246-
const findColumnIndex = (column): boolean => column.type !== DRAG_COLUMN_NAME;
1247+
const findColumnIndex = (column): boolean => this.isFocusableColumn(column);
12471248

12481249
return needFirstColumnIndex
12491250
? allVisibleColumns.findIndex(findColumnIndex)
@@ -1326,6 +1327,10 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
13261327
originalEvent.preventDefault();
13271328
}
13281329

1330+
protected isFocusableColumn(column: Column): boolean {
1331+
return column.type !== DRAG_COLUMN_NAME;
1332+
}
1333+
13291334
public navigateToFirstOrLastCell(needNavigateToFirstCell: boolean, e?: KeyboardEvent): void {
13301335
const firstOrLastColumnIndex = this.getFirstOrLastColumnIndex(needNavigateToFirstCell);
13311336

0 commit comments

Comments
 (0)