Skip to content

Commit 5a50eb0

Browse files
DataGrid - Fix the issue with the focus method not setting the focus to the grid (T1308919) [Part 2] (DevExpress#33299)
(cherry picked from commit 3a48f5d)
1 parent 523fac8 commit 5a50eb0

2 files changed

Lines changed: 64 additions & 14 deletions

File tree

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

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6724,3 +6724,63 @@ test('Focus should be set to the grid to allow keyboard navigation when the focu
67246724
},
67256725
}, '#otherContainer');
67266726
});
6727+
6728+
[true, false].forEach((focusedRowEnabled) => {
6729+
test(`Focus should return to the last active cell when re-entering the rowsview via kbn if focusedRowEnabled=${focusedRowEnabled} (T1308919)`, async (t) => {
6730+
// arrange
6731+
const button = new Button('#otherContainer');
6732+
const dataGrid = new DataGrid('#container');
6733+
const searchPanel = dataGrid.getSearchBox();
6734+
const secondIDCell = dataGrid.getDataCell(1, 0);
6735+
const secondNameCell = dataGrid.getDataCell(1, 1);
6736+
6737+
// assert
6738+
await t.expect(dataGrid.isReady()).ok();
6739+
6740+
// act
6741+
await t
6742+
.click(searchPanel.input)
6743+
.pressKey('tab tab tab tab tab');
6744+
6745+
// assert
6746+
await t.expect(secondIDCell.isFocused).ok();
6747+
6748+
// act
6749+
await searchPanel.focus();
6750+
6751+
// assert
6752+
await t
6753+
.expect(searchPanel.isFocused)
6754+
.ok()
6755+
.expect(secondIDCell.isFocused)
6756+
.notOk('focus should be on the search panel');
6757+
6758+
// act
6759+
await t.pressKey('tab tab tab');
6760+
6761+
// assert
6762+
await t.expect(secondIDCell.isFocused).ok();
6763+
6764+
// act
6765+
await t.pressKey('tab tab');
6766+
6767+
// assert
6768+
await t.expect(button.isFocused).ok();
6769+
6770+
// act
6771+
await t.pressKey('shift+tab');
6772+
6773+
// assert
6774+
await t.expect(secondNameCell.isFocused).ok();
6775+
}).before(async () => {
6776+
await createWidget('dxDataGrid', {
6777+
dataSource: [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }],
6778+
keyExpr: 'id',
6779+
focusedRowEnabled,
6780+
searchPanel: { visible: true },
6781+
});
6782+
await createWidget('dxButton', {
6783+
text: 'Focus receiver',
6784+
}, '#otherContainer');
6785+
});
6786+
});

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,17 +1648,13 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
16481648

16491649
// #region Focusing
16501650
public focus(element) {
1651-
let activeElementSelector;
1652-
const focusedRowEnabled = this.option('focusedRowEnabled');
16531651
const isHighlighted = this._isCellElement($(element));
16541652

16551653
if (!element) {
1656-
activeElementSelector = `.${this.addWidgetPrefix(ROWS_VIEW_CLASS)} .dx-row[tabindex]`;
1657-
if (!focusedRowEnabled) {
1658-
activeElementSelector
1659-
+= `, .${this.addWidgetPrefix(ROWS_VIEW_CLASS)} .dx-row > td[tabindex]`;
1660-
}
1661-
element = this.component.$element().find(activeElementSelector).first();
1654+
const activeRowSelector = `.${this.addWidgetPrefix(ROWS_VIEW_CLASS)} .dx-row[tabindex]`;
1655+
const activeCellSelector = `.${this.addWidgetPrefix(ROWS_VIEW_CLASS)} .dx-row > td[tabindex]`;
1656+
const selectors = [activeRowSelector, activeCellSelector].join(', ');
1657+
element = this.component.$element().find(selectors).first();
16621658
}
16631659

16641660
element && this._focusElement($(element), isHighlighted);
@@ -1786,12 +1782,6 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
17861782
$focusElement
17871783
.removeClass(CELL_FOCUS_DISABLED_CLASS)
17881784
.removeClass(FOCUSED_CLASS);
1789-
1790-
const isTargetInGrid = gridCoreUtils.isElementInCurrentGrid(this, $(e.relatedTarget));
1791-
if (!isTargetInGrid) {
1792-
this._resetFocusedCell(true);
1793-
this._resetFocusedView();
1794-
}
17951785
}
17961786
});
17971787
if (!skipFocusEvent) {

0 commit comments

Comments
 (0)