Skip to content

Commit f14d968

Browse files
authored
DataGrid: Fix cell focus after column reordering when previously the data cell was focused (DevExpress#29941)
Co-authored-by: Alyar <>
1 parent 4e86e03 commit f14d968

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,36 @@ safeSizeTest('The context menu should not have items for column reordering when
258258
});
259259
});
260260

261+
test('The cell focus should be correct after column reordering when previously the data cell was focused', async (t) => {
262+
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
263+
const dataGrid = new DataGrid(DATA_GRID_SELECTOR);
264+
const firstDataCell = dataGrid.getDataCell(0, 0);
265+
266+
await t
267+
.click(firstDataCell.element)
268+
.pressKey('shift+tab')
269+
.pressKey('ctrl+left');
270+
271+
await takeScreenshot(
272+
'cell_focus_after_column_reordering_when_data_cell_was_focused.png',
273+
dataGrid.element,
274+
);
275+
276+
await t
277+
.expect(compareResults.isValid())
278+
.ok(compareResults.errorMessages());
279+
}).before(async () => {
280+
await createWidget('dxDataGrid', {
281+
allowColumnReordering: true,
282+
dataSource: [{
283+
field1: 'test1',
284+
field2: 'test2',
285+
field3: 'test3',
286+
field4: 'test4',
287+
}],
288+
});
289+
});
290+
261291
// Fixed columns
262292
test('reorder fixed left column to right', async (t) => {
263293
const { takeScreenshot, compareResults } = createScreenshotsComparer(t);
Loading

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,16 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
232232
}
233233
}
234234

235-
protected focusOutHandler(): void {
235+
protected focusOutHandler(e): void {
236+
const { relatedTarget } = e;
237+
236238
this._toggleInertAttr(false);
239+
240+
if (relatedTarget && !this.isInsideFocusedView($(relatedTarget))) {
241+
this._isNeedFocus = false;
242+
this._isHiddenFocus = false;
243+
this._isNeedScroll = false;
244+
}
237245
}
238246

239247
protected subscribeToRowsViewFocusEvent(): void {
@@ -1459,10 +1467,8 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
14591467
}
14601468
}
14611469

1462-
private _getFocusedViewByElement($element) {
1463-
const $view = $(this._focusedView?.element());
1464-
1465-
return $element?.closest($view).length !== 0;
1470+
private isInsideFocusedView($element: dxElementWrapper): boolean {
1471+
return $element.closest(this._focusedView?.element()).length !== 0;
14661472
}
14671473

14681474
private _focusView() {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const keyboardNavigationScrollableA11yExtender = (Base: ModuleType<Keyboa
2828
super.focusinHandler(event);
2929
}
3030

31-
protected focusOutHandler(): void {
32-
super.focusOutHandler();
31+
protected focusOutHandler(e): void {
32+
super.focusOutHandler(e);
3333
this.makeScrollableFocusableIfNeed();
3434
}
3535

0 commit comments

Comments
 (0)