From 19729d7136916c36e2c287254cb5580ffa591fc9 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Thu, 12 Nov 2026 17:46:23 +0400 Subject: [PATCH 01/10] fix(grids): keep focused cell focus after partial update --- .../grids/grid_core/focus/m_focus.ts | 27 +++++- .../focus_navigation.integration.test.ts | 82 +++++++++++++++++++ 2 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index 42b7c778e3e6..491a09ed89f2 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -1,4 +1,5 @@ /* eslint-disable max-classes-per-file */ +import type { dxElementWrapper } from '@js/core/renderer'; import $ from '@js/core/renderer'; import { equalByValue } from '@js/core/utils/common'; import { Deferred, type DeferredObj, when } from '@js/core/utils/deferred'; @@ -402,15 +403,31 @@ export class FocusController extends core.ViewController { } } - private _clearPreviousFocusedRow($tableElement, focusedRowIndex) { + public hasStaleFocusedRow(focusedRowIndex: number): boolean { + const rowsView = this.getView('rowsView'); + const $tableElements: dxElementWrapper = rowsView.getTableElements(); + + return $tableElements.toArray().some((tableElement) => { + const $tableElement = $(tableElement); + const $focusedRow = rowsView._getRowElements($tableElement).eq(focusedRowIndex); + + return this.findFocusedRows($tableElement).not($focusedRow).length > 0; + }); + } + + private findFocusedRows($tableElement): dxElementWrapper { const isNotMasterDetailFocusedRow = (_, focusedRow) => { const $focusedRowTable = $(focusedRow).closest(`.${this.addWidgetPrefix(TABLE_POSTFIX_CLASS)}`); return $tableElement.is($focusedRowTable); }; - const $prevRowFocusedElement = $tableElement + return $tableElement .find(FOCUSED_ROW_SELECTOR) .filter(isNotMasterDetailFocusedRow); + } + + private _clearPreviousFocusedRow($tableElement, focusedRowIndex) { + const $prevRowFocusedElement = this.findFocusedRows($tableElement); $prevRowFocusedElement .removeClass(ROW_FOCUSED_CLASS) @@ -632,7 +649,11 @@ const focusDataControllerExtender = ( const isFocusedRowVisible = focusedRowIndex >= 0; const isFocusedRowInChange = !!e.rowIndices?.includes(focusedRowIndex); - if (isFocusedRowVisible && isFocusedRowInChange) { + if ( + isFocusedRowVisible + && isFocusedRowInChange + && this._focusController.hasStaleFocusedRow(focusedRowIndex) + ) { this._focusController.updateFocusedRow({ focusedRowKey, preventScroll: true }); } } diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts new file mode 100644 index 000000000000..a9cf56be4829 --- /dev/null +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -0,0 +1,82 @@ +import { + afterEach, beforeEach, describe, expect, it, jest, +} from '@jest/globals'; +import $ from '@js/core/renderer'; +import type { Properties as TreeListProperties } from '@js/ui/tree_list'; +import TreeList from '@js/ui/tree_list'; + +const TREELIST_CONTAINER_ID = 'treeListContainer'; + +const DATA = [ + { id: 1, parentId: 0, name: 'root A' }, + { id: 11, parentId: 1, name: 'child A1' }, + { id: 111, parentId: 11, name: 'leaf A1a' }, + { id: 2, parentId: 0, name: 'root B' }, + { id: 21, parentId: 2, name: 'child B1' }, +]; + +const flushAsync = async (): Promise => { + jest.runAllTimers(); + await Promise.resolve(); +}; + +const createTreeList = (options: TreeListProperties = {}): { instance: TreeList } => { + const $container = $('
') + .attr('id', TREELIST_CONTAINER_ID) + .appendTo(document.body); + + const instance = new TreeList($container.get(0) as HTMLDivElement, { + keyExpr: 'id', + ...options, + }); + + jest.runAllTimers(); + + return { instance }; +}; + +const visibleKeys = (instance: TreeList): unknown[] => instance + .getVisibleRows() + .map((row) => row.key); + +describe('TreeList focus — partial update of the focused row', () => { + beforeEach(() => { + jest.useFakeTimers(); + }); + + afterEach(() => { + const $container = $(`#${TREELIST_CONTAINER_ID}`); + + (TreeList.getInstance($container.get(0) as HTMLElement) as TreeList)?.dispose(); + $container.remove(); + jest.clearAllMocks(); + jest.useRealTimers(); + }); + + it('keeps DOM focus on the focused cell when the focused row is expanded with repaintChangesOnly (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: DATA, + columns: ['id', 'name'], + focusedRowEnabled: true, + focusedRowKey: 1, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + const cell = instance.getCellElement(0, 'name') as HTMLElement; + instance.focus(cell); + await flushAsync(); + cell.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); + + expect(document.activeElement).toBe(cell); + + const expanding = instance.expandRow(1); + await flushAsync(); + await expanding; + + expect(visibleKeys(instance)).toEqual([1, 11, 2]); + expect(cell.hasAttribute('tabindex')).toBe(true); + expect(document.activeElement).toBe(cell); + }); +}); From 09d2860746797e22dc49f6fea9a6ef2d90f00345 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:30:22 +0400 Subject: [PATCH 02/10] fix(grids): keep focused row tab stop after partial update --- .../grids/grid_core/focus/m_focus.ts | 21 +++++++++++---- .../focus_navigation.integration.test.ts | 26 +++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index 491a09ed89f2..d1ca82c43ad7 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -415,6 +415,15 @@ export class FocusController extends core.ViewController { }); } + public restoreFocusedRowTabIndex(focusedRowIndex: number): void { + const $focusedRows = $(this.getView('rowsView').getRowElement(focusedRowIndex)); + const hasFocusableCell = $focusedRows.children('[tabindex]').length > 0; + + if (!hasFocusableCell) { + $focusedRows.attr('tabindex', this.option('tabindex') || 0); + } + } + private findFocusedRows($tableElement): dxElementWrapper { const isNotMasterDetailFocusedRow = (_, focusedRow) => { const $focusedRowTable = $(focusedRow).closest(`.${this.addWidgetPrefix(TABLE_POSTFIX_CLASS)}`); @@ -649,12 +658,14 @@ const focusDataControllerExtender = ( const isFocusedRowVisible = focusedRowIndex >= 0; const isFocusedRowInChange = !!e.rowIndices?.includes(focusedRowIndex); - if ( - isFocusedRowVisible - && isFocusedRowInChange - && this._focusController.hasStaleFocusedRow(focusedRowIndex) - ) { + if (!isFocusedRowVisible || !isFocusedRowInChange) { + return; + } + + if (this._focusController.hasStaleFocusedRow(focusedRowIndex)) { this._focusController.updateFocusedRow({ focusedRowKey, preventScroll: true }); + } else { + this._focusController.restoreFocusedRowTabIndex(focusedRowIndex); } } diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index a9cf56be4829..aad57a03c9d7 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -79,4 +79,30 @@ describe('TreeList focus — partial update of the focused row', () => { expect(cell.hasAttribute('tabindex')).toBe(true); expect(document.activeElement).toBe(cell); }); + + it('keeps the focused row tab stop when the focused row is expanded with repaintChangesOnly (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: DATA, + columns: ['id', 'name'], + focusedRowEnabled: true, + focusedRowKey: 1, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + const row = $(instance.getRowElement(0)).get(0) as HTMLElement; + instance.focus(row); + await flushAsync(); + row.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); + + expect(document.activeElement).toBe(row); + + const expanding = instance.expandRow(1); + await flushAsync(); + await expanding; + + expect(visibleKeys(instance)).toEqual([1, 11, 2]); + expect(row.hasAttribute('tabindex')).toBe(true); + }); }); From d74d9a2ae7867ddf201c40267d614d86986b9db3 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Fri, 13 Nov 2026 13:52:37 +0400 Subject: [PATCH 03/10] fix(grids): use tabIndex option for restored focused row tab stop --- .../devextreme/js/__internal/grids/grid_core/focus/m_focus.ts | 2 +- .../tree_list/__tests__/focus_navigation.integration.test.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index d1ca82c43ad7..3c2b7246cea8 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -420,7 +420,7 @@ export class FocusController extends core.ViewController { const hasFocusableCell = $focusedRows.children('[tabindex]').length > 0; if (!hasFocusableCell) { - $focusedRows.attr('tabindex', this.option('tabindex') || 0); + $focusedRows.attr('tabindex', this.option('tabIndex') ?? 0); } } diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index aad57a03c9d7..05297af6c8c1 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -88,6 +88,7 @@ describe('TreeList focus — partial update of the focused row', () => { focusedRowKey: 1, repaintChangesOnly: true, autoExpandAll: false, + tabIndex: 3, }); await flushAsync(); @@ -103,6 +104,6 @@ describe('TreeList focus — partial update of the focused row', () => { await expanding; expect(visibleKeys(instance)).toEqual([1, 11, 2]); - expect(row.hasAttribute('tabindex')).toBe(true); + expect(row.getAttribute('tabindex')).toBe('3'); }); }); From a78e45d6a1dc7d2ad730ac28dc52242e0a0370fd Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Mon, 16 Nov 2026 13:19:48 +0400 Subject: [PATCH 04/10] test(grids): drop redundant row element cast in TreeList focus test --- .../tree_list/__tests__/focus_navigation.integration.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index 05297af6c8c1..0fc8c583313f 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -92,7 +92,7 @@ describe('TreeList focus — partial update of the focused row', () => { }); await flushAsync(); - const row = $(instance.getRowElement(0)).get(0) as HTMLElement; + const row = $(instance.getRowElement(0)).get(0); instance.focus(row); await flushAsync(); row.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); From 335826e2f077a7203201eb6cd7238e6376843d20 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:24:22 +0400 Subject: [PATCH 05/10] fix(grids): keep focused row focus when another row is pushed --- .../focus/m_focus.integration.test.ts | 37 +++++++++++++++++++ .../grids/grid_core/focus/m_focus.ts | 32 +++++++++++----- .../focus_navigation.integration.test.ts | 34 +++++++++++++++++ 3 files changed, 93 insertions(+), 10 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts index 4655cbd7ede3..0a804e3c5765 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts @@ -292,6 +292,43 @@ describe('GridCore focus', () => { }); }); + describe('when another row is updated via the store push API with repaintChangesOnly', () => { + it('should keep DOM focus on the focused cell (T1338023)', async () => { + const { instance } = await createDataGrid({ + dataSource: { + store: { + type: 'array', + key: 'id', + data: [ + { id: 1, name: 'Item 1' }, + { id: 2, name: 'Item 2' }, + ], + }, + pushAggregationTimeout: 0, + }, + focusedRowEnabled: true, + focusedRowKey: 1, + repaintChangesOnly: true, + columns: ['id', 'name'], + }); + + const cell = instance.getCellElement(0, 'name') as HTMLElement; + instance.focus(cell); + await flushAsync(); + cell.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); + + expect(document.activeElement).toBe(cell); + + instance.getDataSource().store().push([{ type: 'update', key: 2, data: { name: 'Item 2 updated' } }]); + await flushAsync(); + + expect($(instance.getCellElement(1, 'name')).text()).toBe('Item 2 updated'); + expect(cell.hasAttribute('tabindex')).toBe(true); + expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(false); + expect(document.activeElement).toBe(cell); + }); + }); + describe('when the focused row is reset while the navigation to a virtual row is pending', () => { it('should not focus the row again when the row is rendered', async () => { const rows = Array.from({ length: 100 }, (_, i) => ({ id: i, value: `row ${i}` })); diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index 3c2b7246cea8..7e4589416937 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -404,15 +404,11 @@ export class FocusController extends core.ViewController { } public hasStaleFocusedRow(focusedRowIndex: number): boolean { - const rowsView = this.getView('rowsView'); - const $tableElements: dxElementWrapper = rowsView.getTableElements(); - - return $tableElements.toArray().some((tableElement) => { - const $tableElement = $(tableElement); - const $focusedRow = rowsView._getRowElements($tableElement).eq(focusedRowIndex); + const $tableElements: dxElementWrapper = this.getView('rowsView').getTableElements(); - return this.findFocusedRows($tableElement).not($focusedRow).length > 0; - }); + return $tableElements.toArray().some( + (tableElement) => this.findStaleFocusedRows($(tableElement), focusedRowIndex).length > 0, + ); } public restoreFocusedRowTabIndex(focusedRowIndex: number): void { @@ -435,8 +431,20 @@ export class FocusController extends core.ViewController { .filter(isNotMasterDetailFocusedRow); } + private findStaleFocusedRows($tableElement, focusedRowIndex: number): dxElementWrapper { + const $focusedRows = this.findFocusedRows($tableElement); + + if (focusedRowIndex < 0) { + return $focusedRows; + } + + const $focusedRow = this.getView('rowsView')._getRowElements($tableElement).eq(focusedRowIndex); + + return $focusedRows.not($focusedRow); + } + private _clearPreviousFocusedRow($tableElement, focusedRowIndex) { - const $prevRowFocusedElement = this.findFocusedRows($tableElement); + const $prevRowFocusedElement = this.findStaleFocusedRows($tableElement, focusedRowIndex); $prevRowFocusedElement .removeClass(ROW_FOCUSED_CLASS) @@ -460,7 +468,11 @@ export class FocusController extends core.ViewController { const rowsView = this.getView('rowsView'); $row = $(rowsView._getRowElements($tableElement).eq(focusedRowIndex)); - $row.addClass(ROW_FOCUSED_CLASS).attr('tabindex', tabIndex); + $row.addClass(ROW_FOCUSED_CLASS); + + if (!$row.children('[tabindex]').length) { + $row.attr('tabindex', tabIndex); + } } return $row; diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index 0fc8c583313f..b46a60dd70b7 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -106,4 +106,38 @@ describe('TreeList focus — partial update of the focused row', () => { expect(visibleKeys(instance)).toEqual([1, 11, 2]); expect(row.getAttribute('tabindex')).toBe('3'); }); + + it('keeps DOM focus on the focused cell when another row is updated via push (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: { + store: { + type: 'array', + key: 'id', + data: DATA.map((item) => ({ ...item })), + }, + pushAggregationTimeout: 0, + }, + columns: ['id', 'name'], + focusedRowEnabled: true, + focusedRowKey: 1, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + const cell = instance.getCellElement(0, 'name') as HTMLElement; + instance.focus(cell); + await flushAsync(); + cell.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); + + expect(document.activeElement).toBe(cell); + + instance.getDataSource().store().push([{ type: 'update', key: 2, data: { name: 'root B updated' } }]); + await flushAsync(); + + expect($(instance.getCellElement(1, 'name')).text()).toBe('root B updated'); + expect(cell.hasAttribute('tabindex')).toBe(true); + expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(false); + expect(document.activeElement).toBe(cell); + }); }); From 42823295d15e677cdd98a3b6e0e78e3678db24f0 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:25:18 +0400 Subject: [PATCH 06/10] fix(grids): keep focused row tab stop on in-place row update --- .../focus/m_focus.integration.test.ts | 25 ++++++++++++++++++ .../grids/grid_core/focus/m_focus.ts | 6 +++++ .../focus_navigation.integration.test.ts | 26 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts index 0a804e3c5765..7e9c3ca5b70c 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts @@ -329,6 +329,31 @@ describe('GridCore focus', () => { }); }); + describe('when the focused row has an expanded master detail', () => { + it('should not make the detail row a tab stop (T1338023)', async () => { + const { instance } = await createDataGrid({ + dataSource: [ + { id: 1, name: 'Item 1' }, + { id: 2, name: 'Item 2' }, + ], + keyExpr: 'id', + focusedRowEnabled: true, + focusedRowKey: 1, + columns: ['id', 'name'], + masterDetail: { + enabled: true, + template: (container) => { $(container).text('detail'); }, + }, + }); + + await instance.expandRow(1); + await flushAsync(); + + expect(instance.getVisibleRows()[1].rowType).toBe('detail'); + expect($(instance.getRowElement(1)).get(0).hasAttribute('tabindex')).toBe(false); + }); + }); + describe('when the focused row is reset while the navigation to a virtual row is pending', () => { it('should not focus the row again when the row is rendered', async () => { const rows = Array.from({ length: 100 }, (_, i) => ({ id: i, value: `row ${i}` })); diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index 7e4589416937..a11a0e14cc5e 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -962,6 +962,12 @@ const rowsView = (Base: ModuleType) => class RowsViewFocusController e if (this.option('focusedRowEnabled') && row) { if (this._focusController.isRowFocused(row.key)) { $row.addClass(ROW_FOCUSED_CLASS); + + const isFocusableRow = row.rowType === 'data' || row.rowType === 'group'; + + if (isFocusableRow && !this._keyboardNavigationController.isCellFocusType()) { + $row.attr('tabindex', this.option('tabIndex') ?? 0); + } } } diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index b46a60dd70b7..cdb52a6b2d81 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -77,6 +77,7 @@ describe('TreeList focus — partial update of the focused row', () => { expect(visibleKeys(instance)).toEqual([1, 11, 2]); expect(cell.hasAttribute('tabindex')).toBe(true); + expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(false); expect(document.activeElement).toBe(cell); }); @@ -107,6 +108,31 @@ describe('TreeList focus — partial update of the focused row', () => { expect(row.getAttribute('tabindex')).toBe('3'); }); + it('never removes the tab stop from the focused row while it is expanded with repaintChangesOnly (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: DATA, + columns: ['id', 'name'], + focusedRowEnabled: true, + focusedRowKey: 1, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + const row = $(instance.getRowElement(0)).get(0); + instance.focus(row); + await flushAsync(); + const removeAttribute = jest.spyOn(row, 'removeAttribute'); + + const expanding = instance.expandRow(1); + await flushAsync(); + await expanding; + + expect(visibleKeys(instance)).toEqual([1, 11, 2]); + expect(removeAttribute).not.toHaveBeenCalledWith('tabindex'); + expect(document.activeElement).toBe(row); + }); + it('keeps DOM focus on the focused cell when another row is updated via push (T1338023)', async () => { const { instance } = createTreeList({ dataSource: { From b0c14ba64fdf8984ad423523d0fdfff436db4557 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:25:46 +0400 Subject: [PATCH 07/10] fix(grids): use tabIndex option for the focused row tab stop --- .../focus/m_focus.integration.test.ts | 21 +++++++++++++++++++ .../grids/grid_core/focus/m_focus.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts index 7e9c3ca5b70c..705bc5260af3 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts @@ -329,6 +329,27 @@ describe('GridCore focus', () => { }); }); + describe('when focusedRowKey is changed with a custom tabIndex', () => { + it('should apply the tabIndex option to the new focused row (T1338023)', async () => { + const { instance } = await createDataGrid({ + dataSource: [ + { id: 1, name: 'Item 1' }, + { id: 2, name: 'Item 2' }, + ], + keyExpr: 'id', + focusedRowEnabled: true, + focusedRowKey: 1, + tabIndex: 3, + columns: ['id', 'name'], + }); + + instance.option('focusedRowKey', 2); + await flushAsync(); + + expect($(instance.getRowElement(1)).get(0).getAttribute('tabindex')).toBe('3'); + }); + }); + describe('when the focused row has an expanded master detail', () => { it('should not make the detail row a tab stop (T1338023)', async () => { const { instance } = await createDataGrid({ diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index a11a0e14cc5e..e909b71ae5e0 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -464,7 +464,7 @@ export class FocusController extends core.ViewController { if (changedItem && (changedItem.rowType === 'data' || changedItem.rowType === 'group')) { const { focusedRowIndex } = options; const { $tableElement } = options; - const tabIndex = this.option('tabindex') || 0; + const tabIndex = this.option('tabIndex') ?? 0; const rowsView = this.getView('rowsView'); $row = $(rowsView._getRowElements($tableElement).eq(focusedRowIndex)); From 245a5187e18eb9c9d89dabf39f29ca58fc390e67 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:26:20 +0400 Subject: [PATCH 08/10] fix(grids): clear first row tab stop after partial update of the focused row --- .../grids/grid_core/focus/m_focus.ts | 33 ++----------------- .../focus_navigation.integration.test.ts | 31 +++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index e909b71ae5e0..c4bc31539f5d 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -403,36 +403,15 @@ export class FocusController extends core.ViewController { } } - public hasStaleFocusedRow(focusedRowIndex: number): boolean { - const $tableElements: dxElementWrapper = this.getView('rowsView').getTableElements(); - - return $tableElements.toArray().some( - (tableElement) => this.findStaleFocusedRows($(tableElement), focusedRowIndex).length > 0, - ); - } - - public restoreFocusedRowTabIndex(focusedRowIndex: number): void { - const $focusedRows = $(this.getView('rowsView').getRowElement(focusedRowIndex)); - const hasFocusableCell = $focusedRows.children('[tabindex]').length > 0; - - if (!hasFocusableCell) { - $focusedRows.attr('tabindex', this.option('tabIndex') ?? 0); - } - } - - private findFocusedRows($tableElement): dxElementWrapper { + private findStaleFocusedRows($tableElement, focusedRowIndex: number): dxElementWrapper { const isNotMasterDetailFocusedRow = (_, focusedRow) => { const $focusedRowTable = $(focusedRow).closest(`.${this.addWidgetPrefix(TABLE_POSTFIX_CLASS)}`); return $tableElement.is($focusedRowTable); }; - return $tableElement + const $focusedRows = $tableElement .find(FOCUSED_ROW_SELECTOR) .filter(isNotMasterDetailFocusedRow); - } - - private findStaleFocusedRows($tableElement, focusedRowIndex: number): dxElementWrapper { - const $focusedRows = this.findFocusedRows($tableElement); if (focusedRowIndex < 0) { return $focusedRows; @@ -670,14 +649,8 @@ const focusDataControllerExtender = ( const isFocusedRowVisible = focusedRowIndex >= 0; const isFocusedRowInChange = !!e.rowIndices?.includes(focusedRowIndex); - if (!isFocusedRowVisible || !isFocusedRowInChange) { - return; - } - - if (this._focusController.hasStaleFocusedRow(focusedRowIndex)) { + if (isFocusedRowVisible && isFocusedRowInChange) { this._focusController.updateFocusedRow({ focusedRowKey, preventScroll: true }); - } else { - this._focusController.restoreFocusedRowTabIndex(focusedRowIndex); } } diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index cdb52a6b2d81..9fae9d1ea286 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -133,6 +133,37 @@ describe('TreeList focus — partial update of the focused row', () => { expect(document.activeElement).toBe(row); }); + it('moves the tab stop from the first row to the focused row when its hidden focused row is expanded (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: [ + { id: 1, parentId: 0, name: 'root A' }, + { id: 2, parentId: 0, name: 'root B' }, + { id: 21, parentId: 2, name: 'child B1' }, + { id: 3, parentId: 0, name: 'root C' }, + ], + columns: ['id', 'name'], + focusedRowEnabled: true, + focusedRowKey: 21, + autoNavigateToFocusedRow: false, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + instance.repaint(); + await flushAsync(); + + expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(true); + + const expanding = instance.expandRow(2); + await flushAsync(); + await expanding; + + expect(visibleKeys(instance)).toEqual([1, 2, 21, 3]); + expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(false); + expect($(instance.getRowElement(2)).get(0).hasAttribute('tabindex')).toBe(true); + }); + it('keeps DOM focus on the focused cell when another row is updated via push (T1338023)', async () => { const { instance } = createTreeList({ dataSource: { From 1b48d41f69f8568e8c0b29be033a5ce88b8a0a49 Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:26:50 +0400 Subject: [PATCH 09/10] fix(grids): keep focused group row tab stop in cell focus mode --- .../focus/m_focus.integration.test.ts | 43 +++++++++++++++++++ .../grids/grid_core/focus/m_focus.ts | 5 ++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts index 705bc5260af3..6a15573a2935 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts @@ -329,6 +329,49 @@ describe('GridCore focus', () => { }); }); + describe('when a focused group row is updated via the store push API with repaintChangesOnly', () => { + it('should keep DOM focus on the group row in cell focus mode (T1338023)', async () => { + const { instance } = await createDataGrid({ + dataSource: { + store: { + type: 'array', + key: 'id', + data: [ + { id: 1, group: 'A', value: 1 }, + { id: 2, group: 'A', value: 2 }, + { id: 3, group: 'B', value: 3 }, + ], + }, + reshapeOnPush: true, + pushAggregationTimeout: 0, + }, + columns: ['id', { dataField: 'group', groupIndex: 0 }, 'value'], + summary: { groupItems: [{ column: 'value', summaryType: 'sum' }] }, + focusedRowEnabled: true, + repaintChangesOnly: true, + }); + + const cell = instance.getCellElement(1, 'id') as HTMLElement; + instance.focus(cell); + await flushAsync(); + cell.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp', bubbles: true })); + await flushAsync(); + const groupRow = $(instance.getRowElement(0)).get(0); + groupRow.dispatchEvent(new KeyboardEvent('keydown', { key: 'Shift', bubbles: true })); + + expect(instance.option('focusedRowKey')).toEqual(['A']); + expect(document.activeElement).toBe(groupRow); + + const removeAttribute = jest.spyOn(groupRow, 'removeAttribute'); + instance.getDataSource().store().push([{ type: 'update', key: 1, data: { value: 100 } }]); + await flushAsync(); + + expect($(instance.getRowElement(0)).text()).toContain('102'); + expect(removeAttribute).not.toHaveBeenCalledWith('tabindex'); + expect(document.activeElement).toBe(groupRow); + }); + }); + describe('when focusedRowKey is changed with a custom tabIndex', () => { it('should apply the tabIndex option to the new focused row (T1338023)', async () => { const { instance } = await createDataGrid({ diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts index c4bc31539f5d..d5c80b5693bc 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.ts @@ -936,9 +936,10 @@ const rowsView = (Base: ModuleType) => class RowsViewFocusController e if (this._focusController.isRowFocused(row.key)) { $row.addClass(ROW_FOCUSED_CLASS); - const isFocusableRow = row.rowType === 'data' || row.rowType === 'group'; + const isRowTabStop = row.rowType === 'group' + || (row.rowType === 'data' && !this._keyboardNavigationController.isCellFocusType()); - if (isFocusableRow && !this._keyboardNavigationController.isCellFocusType()) { + if (isRowTabStop) { $row.attr('tabindex', this.option('tabIndex') ?? 0); } } From 8a3ae58de55a000bd6fea18d1a6a45ae39f06cfc Mon Sep 17 00:00:00 2001 From: Maksim Zakharov <251575087+bit-byte0@users.noreply.github.com> Date: Tue, 17 Nov 2026 15:29:40 +0400 Subject: [PATCH 10/10] fix(grids): keep focus state classes on in-place row update --- .../focus/m_focus.integration.test.ts | 2 ++ .../m_keyboard_navigation.ts | 11 +++++++ .../focus_navigation.integration.test.ts | 33 +++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts index 6a15573a2935..eeda6f7295c8 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/focus/m_focus.integration.test.ts @@ -361,6 +361,7 @@ describe('GridCore focus', () => { expect(instance.option('focusedRowKey')).toEqual(['A']); expect(document.activeElement).toBe(groupRow); + expect(groupRow.classList.contains('dx-focused')).toBe(true); const removeAttribute = jest.spyOn(groupRow, 'removeAttribute'); instance.getDataSource().store().push([{ type: 'update', key: 1, data: { value: 100 } }]); @@ -368,6 +369,7 @@ describe('GridCore focus', () => { expect($(instance.getRowElement(0)).text()).toContain('102'); expect(removeAttribute).not.toHaveBeenCalledWith('tabindex'); + expect(groupRow.classList.contains('dx-focused')).toBe(true); expect(document.activeElement).toBe(groupRow); }); }); diff --git a/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts b/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts index 02727c53cb08..c1c9d15ea497 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/keyboard_navigation/m_keyboard_navigation.ts @@ -3008,6 +3008,17 @@ const rowsView = (Base: ModuleType) => class RowsViewKeyboardExtender } } + protected _updateCells($rowElement, $newRowElement, columnIndices, options?): void { + const focusStateClasses = [FOCUSED_CLASS, CELL_FOCUS_DISABLED_CLASS] + .filter((className) => $rowElement.hasClass(className)); + + super._updateCells($rowElement, $newRowElement, columnIndices, options); + + focusStateClasses.forEach((className) => { + $rowElement.addClass(className); + }); + } + public renderFocusState(params) { super.renderFocusState(params); diff --git a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts index 9fae9d1ea286..e13e2c2cf706 100644 --- a/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts +++ b/packages/devextreme/js/__internal/grids/tree_list/__tests__/focus_navigation.integration.test.ts @@ -4,6 +4,7 @@ import { import $ from '@js/core/renderer'; import type { Properties as TreeListProperties } from '@js/ui/tree_list'; import TreeList from '@js/ui/tree_list'; +import eventsEngine from '@ts/events/core/m_events_engine'; const TREELIST_CONTAINER_ID = 'treeListContainer'; @@ -35,6 +36,12 @@ const createTreeList = (options: TreeListProperties = {}): { instance: TreeList return { instance }; }; +const click = (element: Element): void => { + eventsEngine.trigger(element, 'dxpointerdown'); + eventsEngine.trigger(element, 'dxpointerup'); + eventsEngine.trigger(element, 'dxclick'); +}; + const visibleKeys = (instance: TreeList): unknown[] => instance .getVisibleRows() .map((row) => row.key); @@ -197,4 +204,30 @@ describe('TreeList focus — partial update of the focused row', () => { expect($(instance.getRowElement(0)).get(0).hasAttribute('tabindex')).toBe(false); expect(document.activeElement).toBe(cell); }); + + it('keeps the pointer focus state of the focused row when it is expanded with repaintChangesOnly (T1338023)', async () => { + const { instance } = createTreeList({ + dataSource: DATA, + columns: ['id', 'name'], + focusedRowEnabled: true, + repaintChangesOnly: true, + autoExpandAll: false, + }); + await flushAsync(); + + const row = $(instance.getRowElement(0)).get(0); + click(instance.getCellElement(0, 'name') as HTMLElement); + await flushAsync(); + + expect(instance.option('focusedRowKey')).toBe(1); + expect(row.classList.contains('dx-cell-focus-disabled')).toBe(true); + + const expanding = instance.expandRow(1); + await flushAsync(); + await expanding; + + expect(visibleKeys(instance)).toEqual([1, 11, 2]); + expect(row.classList.contains('dx-cell-focus-disabled')).toBe(true); + expect(row.classList.contains('dx-focused')).toBe(false); + }); });