Skip to content

Commit b95934d

Browse files
authored
Merge pull request #8240 from IgniteUI/teodosiah/add-new-row-keyboard-nav
feat(grid): initial implemantation
2 parents 2b5c0d6 + b87809f commit b95934d

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export const NAVIGATION_KEYS = new Set([
324324
]);
325325
export const ROW_EXPAND_KEYS = new Set('right down arrowright arrowdown'.split(' '));
326326
export const ROW_COLLAPSE_KEYS = new Set('left up arrowleft arrowup'.split(' '));
327-
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'enter', 'f2', 'escape', 'esc', 'pagedown', 'pageup']);
327+
export const SUPPORTED_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'enter', 'f2', 'escape', 'esc', 'pagedown', 'pageup', '+']);
328328
export const HEADER_KEYS = new Set([...Array.from(NAVIGATION_KEYS), 'escape', 'esc' , 'l']);
329329

330330
/**

projects/igniteui-angular/src/lib/grids/grid-navigation.service.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export class IgxGridNavigationService {
5050
if (!this.activeNode || !(SUPPORTED_KEYS.has(key) || (key === 'tab' && this.grid.crudService.cell))) { return; }
5151
const shift = event.shiftKey;
5252
const ctrl = event.ctrlKey;
53+
const alt = event.altKey;
5354
if (NAVIGATION_KEYS.has(key) && this.pendingNavigation) { event.preventDefault(); return; }
5455

5556
const type = this.isDataRow(this.activeNode.row) ? 'dataCell' :
@@ -262,9 +263,20 @@ export class IgxGridNavigationService {
262263
protected handleAlt(key: string, event: KeyboardEvent) {
263264
event.preventDefault();
264265
const row = this.grid.getRowByIndex(this.activeNode.row) as any;
265-
if (!this.isToggleKey(key) || !row) { return; }
266266

267-
if (!row.expanded && ROW_EXPAND_KEYS.has(key)) {
267+
if (!(this.isToggleKey(key) || this.isAddKey(key)) || !row) { return; }
268+
if (this.isAddKey(key)) {
269+
if (!this.grid.rowEditable) {
270+
console.warn('The grid must be in row edit mode to perform row adding!');
271+
return;
272+
}
273+
274+
if (event.shiftKey && row.treeRow !== undefined) {
275+
row.beginAddChild();
276+
} else if (!event.shiftKey) {
277+
row.beginAddRow();
278+
}
279+
} else if (!row.expanded && ROW_EXPAND_KEYS.has(key)) {
268280
row.rowID === undefined ? row.toggle() :
269281
this.grid.gridAPI.set_row_expansion_state(row.rowID, true, event);
270282
} else if (row.expanded && ROW_COLLAPSE_KEYS.has(key)) {
@@ -607,4 +619,8 @@ export class IgxGridNavigationService {
607619
private isToggleKey(key: string): boolean {
608620
return ROW_COLLAPSE_KEYS.has(key) || ROW_EXPAND_KEYS.has(key);
609621
}
622+
623+
private isAddKey(key: string): boolean {
624+
return key === '+';
625+
}
610626
}

projects/igniteui-angular/src/lib/grids/grid/grid-add-row.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,28 @@ describe('IgxGrid - Row Adding #grid', () => {
9898
// No much space between the row and the banner
9999
expect(addRowTop - bannerBottom).toBeLessThan(2);
100100
});
101+
it('Should be able to enter add row mode on Alt + plus key.', () => {
102+
GridFunctions.focusFirstCell(fixture);
103+
fixture.detectChanges();
104+
105+
UIInteractions.triggerEventHandlerKeyDown('+', gridContent, true, false, false);
106+
fixture.detectChanges();
107+
108+
const addRow = grid.getRowByIndex(1);
109+
expect(addRow.addRow).toBeTrue();
101110

111+
});
112+
it('Should not be able to enter add row mode on Alt + Shift + plus key.', () => {
113+
GridFunctions.focusFirstCell(fixture);
114+
fixture.detectChanges();
115+
116+
UIInteractions.triggerEventHandlerKeyDown('+', gridContent, true, true, false);
117+
fixture.detectChanges();
118+
119+
const banner = GridFunctions.getRowEditingOverlay(fixture);
120+
expect(banner).toBeNull();
121+
expect(grid.getRowByIndex(1).addRow).toBeFalse();
122+
});
102123
it('Should not be able to enter add row mode when rowEditing is disabled', () => {
103124
grid.rowEditable = false;
104125
fixture.detectChanges();

src/app/grid-add-row/grid-add-row.sample.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export class GridAddRowSampleComponent implements OnInit {
1313

1414
data: any[];
1515
columns: any[];
16-
1716
onMouseOver(event, grid, actionStrip) {
1817
if (event.target.nodeName.toLowerCase() === 'igx-grid-cell') {
1918
const rowIndex = parseInt(event.target.attributes['data-rowindex'].value, 10);

0 commit comments

Comments
 (0)