Skip to content

Commit 1b59851

Browse files
DataGrid - Fix incorrect onFocusedCellChanged parameters when focusing the first cell (T1282664) (#32968)
1 parent 123e120 commit 1b59851

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4269,6 +4269,52 @@ test('DataGrid - focusedRowIndex is -1 when the first data cell is focused with
42694269
},
42704270
}));
42714271

4272+
test('DataGrid - onFocusedCellChanged parameters should be correct when focusing the first cell (T1282664)', async (t) => {
4273+
const dataGrid = new DataGrid('#container');
4274+
4275+
// act
4276+
await t
4277+
.click(dataGrid.getSearchBox().input)
4278+
.pressKey('tab tab tab');
4279+
4280+
// assert
4281+
const firstDataCell = dataGrid.getDataCell(0, 0).element;
4282+
await t
4283+
.expect(firstDataCell.focused)
4284+
.ok();
4285+
4286+
const expectedFocusedCellChangedEventArgs = {
4287+
cellElement: firstDataCell,
4288+
columnIndex: 0,
4289+
row: {
4290+
data: {
4291+
field_0: 'val_0_0',
4292+
field_1: 'val_0_1',
4293+
},
4294+
},
4295+
rowIndex: 0,
4296+
};
4297+
await checkFocusedCellChangedEventArgs(t, expectedFocusedCellChangedEventArgs);
4298+
}).before(async () => {
4299+
await resetFocusedEventsTestData();
4300+
4301+
await createWidget('dxDataGrid', {
4302+
dataSource: getData(1, 2),
4303+
keyExpr: 'field_0',
4304+
showBorders: true,
4305+
searchPanel: {
4306+
visible: true,
4307+
},
4308+
onFocusedCellChanged(e) {
4309+
(window as any).focusedEventsTestData.push({ name: 'onFocusedCellChanged', args: e });
4310+
},
4311+
});
4312+
}).after(async () => {
4313+
await ClientFunction(() => {
4314+
delete (window as any).focusedEventsTestData;
4315+
})();
4316+
});
4317+
42724318
test('DataGrid - Cell focus in edit mode does not work correctly if a cell has a disabled editor (T1177434)', async (t) => {
42734319
const dataGrid = new DataGrid('#container');
42744320
await t

e2e/testcafe-devextreme/tests/dataGrid/helpers/eventUtils.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const getFocusedCellChangedEventArgs = ClientFunction(
3535
.args;
3636

3737
return {
38+
cellElementText: eventArgs.cellElement.get(0).textContent,
3839
columnIndex: eventArgs.columnIndex,
40+
row: {
41+
data: eventArgs.row.data,
42+
},
3943
rowIndex: eventArgs.rowIndex,
4044
};
4145
},
@@ -102,7 +106,11 @@ export const checkFocusedRowChangingEventArgs = async (
102106
export const checkFocusedCellChangedEventArgs = async (
103107
t: TestController,
104108
expectedArgs: {
109+
cellElement?: Selector;
105110
columnIndex: number;
111+
row?: {
112+
data: any;
113+
};
106114
rowIndex: number;
107115
},
108116
): Promise<void> => {
@@ -113,6 +121,19 @@ export const checkFocusedCellChangedEventArgs = async (
113121
.eql(expectedArgs.columnIndex)
114122
.expect(args.rowIndex)
115123
.eql(expectedArgs.rowIndex);
124+
125+
if (expectedArgs.row?.data) {
126+
await t
127+
.expect(args.row.data)
128+
.eql(expectedArgs.row.data);
129+
}
130+
131+
if (expectedArgs.cellElement) {
132+
const expectedCellElementText = await expectedArgs.cellElement.textContent;
133+
await t
134+
.expect(args.cellElementText)
135+
.eql(expectedCellElementText);
136+
}
116137
};
117138

118139
export const checkFocusedRowChangedEventArgs = async (

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
239239
const isCell = $element.is('td');
240240
const needSetFocusPosition = (this.option('focusedRowIndex') ?? -1) < 0;
241241
if (isCell && needSetFocusPosition) {
242+
this._focusView();
242243
this._updateFocusedCellPosition($element);
243244
}
244245
}

0 commit comments

Comments
 (0)