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
Expand Up @@ -50,6 +50,10 @@ describe('Keyboard Navigation', () => {
const SELECTION_OPTIONS: DataGridProperties = {
selection: { mode: 'multiple', showCheckBoxesMode: 'none' },
};
const COMMAND_MODIFIERS = [
{ modifierName: 'Ctrl', modifiers: { ctrlKey: true } },
{ modifierName: 'Meta', modifiers: { metaKey: true } },
];

const getRowKey = (element: Element | null): number | undefined => {
const row = element?.closest<HTMLTableRowElement>('tr.dx-data-row');
Expand Down Expand Up @@ -608,6 +612,30 @@ describe('Keyboard Navigation', () => {
expect(instance.getController('editing').isEditing()).toBe(false);
});

it.each(COMMAND_MODIFIERS)(
'should not prevent the default action of $modifierName+c pressed while the rows are rendering',
async ({ modifiers }) => {
const { instance, renderPendingTemplates } = await focusRowAndScrollDown(
false,
1,
EDITING_OPTIONS,
);

const { preventDefault, stopPropagation } = triggerKeyDown(
instance,
'c',
document.activeElement,
modifiers,
);
jest.runAllTimers();
renderPendingTemplates();

expect(preventDefault).toHaveBeenCalledTimes(0);
expect(stopPropagation).toHaveBeenCalledTimes(0);
expect(instance.getController('editing').isEditing()).toBe(false);
},
);

it('should select all rows on Meta+A pressed while the rows are rendering', async () => {
const { instance } = await focusRowAndScrollDown(false, 1, {
...EDITING_OPTIONS,
Expand Down Expand Up @@ -1168,4 +1196,52 @@ describe('Keyboard Navigation', () => {
},
);
});

describe('command shortcuts pressed with editOnKeyPress (T1337924)', () => {
const COMMAND_SHORTCUT_CASES = ['c', 'v', 'x', 'z'].flatMap(
(keyName) => COMMAND_MODIFIERS.map((modifier) => ({ keyName, ...modifier })),
);

const focusEditableCell = async (): Promise<DataGridInstance> => {
const { instance, component } = await createDataGrid({
dataSource: DATA_SOURCE.slice(0, 3),
keyExpr: 'id',
columns: ['id', 'name'],
editing: { mode: 'cell', allowUpdating: true },
keyboardNavigation: { editOnKeyPress: true },
});
triggerPointerDown(component.getDataCell(0, 1).getElement() as HTMLElement);
jest.runAllTimers();

return instance;
};

it('should start editing the focused cell on c pressed', async () => {
const instance = await focusEditableCell();

triggerKeyDown(instance, 'c');
jest.runAllTimers();

expect(instance.getController('editing').isEditing()).toBe(true);
});

it.each(COMMAND_SHORTCUT_CASES)(
'should not start editing on $modifierName+$keyName pressed',
async ({ keyName, modifiers }) => {
const instance = await focusEditableCell();

const { preventDefault, stopPropagation } = triggerKeyDown(
instance,
keyName,
undefined,
modifiers,
);
jest.runAllTimers();

expect(instance.getController('editing').isEditing()).toBe(false);
expect(preventDefault).toHaveBeenCalledTimes(0);
expect(stopPropagation).toHaveBeenCalledTimes(0);
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,10 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo

private isFocusedCellKey(eventArgs: KeyboardKeyDownEvent): boolean {
const {
keyName, key, ctrl, alt, originalEvent,
keyName, key, ctrl, originalEvent,
} = eventArgs;
const isViewSwitch = ctrl && (keyName === 'upArrow' || keyName === 'downArrow');
const isCommandShortcut = isCommandKeyPressed(originalEvent) && (keyName === 'A' || keyName === 'F');
const isFastEditingKey = key?.length === 1
&& !ctrl && !alt && !isCommandShortcut
&& !!this._isFastEditingAllowed();
const isFastEditingKey = key?.length === 1 && this.canBeginFastEditing(originalEvent);

return !isViewSwitch && (FOCUSED_CELL_KEYS.includes(keyName) || isFastEditingKey);
}
Expand Down Expand Up @@ -1445,13 +1442,15 @@ export class KeyboardNavigationController extends KeyboardNavigationControllerCo
return false;
}

private canBeginFastEditing(originalEvent): boolean {
return !!this._isFastEditingAllowed()
&& !originalEvent.altKey
&& !isCommandKeyPressed(originalEvent)
&& !this._editingController.isEditing();
}

private _beginFastEditing(originalEvent, isDeleting?) {
if (
!this._isFastEditingAllowed()
|| originalEvent.altKey
|| originalEvent.ctrlKey
|| this._editingController.isEditing()
) {
if (!this.canBeginFastEditing(originalEvent)) {
return false;
}

Expand Down
Loading