Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Selector, ClientFunction } from 'testcafe';
import { createScreenshotsComparer } from 'devextreme-screenshot-comparer';
import Button from 'devextreme-testcafe-models/button';
import DataGrid from 'devextreme-testcafe-models/dataGrid';
import CommandCell from 'devextreme-testcafe-models/dataGrid/commandCell';
import { ClassNames } from 'devextreme-testcafe-models/dataGrid/classNames';
Expand Down Expand Up @@ -6576,3 +6577,66 @@ test('The last cell should be focused after changing the page size (T1063530)',
})();
});
});

test('Focus should be set to the grid to allow keyboard navigation when the focus method is called (T1308919)', async (t) => {
// arrange
const button = new Button('#otherContainer');
const dataGrid = new DataGrid('#container');
const firstDataCell = dataGrid.getDataCell(0, 0);
const firstRow = dataGrid.getDataRow(0);
const secondRow = dataGrid.getDataRow(1);

// assert
await t.expect(dataGrid.isReady()).ok();

// act
await dataGrid.apiFocus(firstDataCell.element);

// assert
await t
.expect(firstDataCell.isFocused).ok()
.expect(firstRow.isFocusedRow).ok();

// act
await button.focus();

// assert
await t
.expect(button.isFocused)
.ok()
.expect(firstDataCell.isFocused)
.notOk('focus should be on the button')
.expect(firstRow.isFocusedRow)
.ok('row should still have the focused-row style');

// act
await t.pressKey('down');

// assert
await t
.expect(secondRow.isFocusedRow)
.notOk('grid kbn should not work');

// act
await t
.pressKey('enter') // trigger button click
.pressKey('down');

// assert
await t
.expect(secondRow.isFocusedRow)
.ok('grid is focused, so kbn should work');
}).before(async () => {
await createWidget('dxDataGrid', {
dataSource: [{ id: 1, name: 'test1' }, { id: 2, name: 'test2' }],
keyExpr: 'id',
focusedRowEnabled: true,
});
await createWidget('dxButton', {
text: 'Focus Grid',
onClick() {
const grid = ($ as any)('#container').dxDataGrid('instance');
grid.focus();
},
}, '#otherContainer');
});
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,12 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
$focusElement
.removeClass(CELL_FOCUS_DISABLED_CLASS)
.removeClass(FOCUSED_CLASS);

const isTargetInGrid = gridCoreUtils.isElementInCurrentGrid(this, $(e.relatedTarget));
if (!isTargetInGrid) {
this._resetFocusedCell(true);
this._resetFocusedView();
}
}
});
if (!skipFocusEvent) {
Expand Down
11 changes: 3 additions & 8 deletions packages/testcafe-models/dataGrid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,17 +724,12 @@ export default class DataGrid extends GridCore {
)();
}


apiFocus(): Promise<void> {
apiFocus(cellElement?: Selector): Promise<void> {
const { getInstance } = this;

return ClientFunction(
() => (getInstance() as any).focus(),
{
dependencies: {
getInstance,
},
},
() => (getInstance() as any).focus(cellElement?.()),
{ dependencies: { getInstance, cellElement } },
)();
}

Expand Down
Loading