Skip to content

Commit 7d77849

Browse files
committed
feat(grid): deselect cell with ctrl + click
1 parent 2cde0ce commit 7d77849

File tree

5 files changed

+21
-13
lines changed

5 files changed

+21
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes for each version of this project will be documented in this
66

77
- `IgxGrid`
88
- Added new auto-sizing API `recalculateAutoSizes` that recalculates widths of columns that have size set to `auto`. Can be used in scenarios where you want to auto-size the columns again post initialization.
9+
- Clicking with the Left Mouse key while holding `Ctrl` on selected cell will deselect the cell.
910
- `igxPivotGrid`
1011
- Adding `aggregatorName` for pivot value configuration as an alternative to setting `aggregator` function. If both are set `aggregatorName` takes precedent. If none are set an error is thrown.
1112

projects/igniteui-angular/src/lib/grids/cell.component.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
973973
this.grid.crudService.updateCell(true, event);
974974
}
975975
return;
976+
} else {
977+
this.selectionService.primaryButton = true;
976978
}
977979
this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
978980
this.activate(event);
@@ -1030,8 +1032,8 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
10301032
*/
10311033
public activate(event: FocusEvent | KeyboardEvent) {
10321034
const node = this.selectionNode;
1033-
const shouldEmitSelection = !this.selectionService.isActiveNode(node);
1034-
1035+
let shouldEmitSelection = !this.selectionService.isActiveNode(node);
1036+
10351037
if (this.selectionService.primaryButton) {
10361038
const currentActive = this.selectionService.activeElement;
10371039
this.selectionService.activeElement = node;
@@ -1066,8 +1068,13 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
10661068
}
10671069
this.selectionService.primaryButton = true;
10681070
if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
1069-
this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
1070-
this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
1071+
if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any).ctrlKey) {
1072+
this.selectionService.remove(this.selectionService.activeElement);
1073+
shouldEmitSelection = true;
1074+
} else {
1075+
this.selectionService.add(this.selectionService.activeElement, false); // pointer events handle range generation
1076+
this.selectionService.keyboardStateOnFocus(node, this.grid.rangeSelected, this.nativeElement);
1077+
}
10711078
}
10721079
if (this.grid.isCellSelectable && shouldEmitSelection) {
10731080
this.zone.run(() => this.grid.selected.emit({ cell: this.getCellType(), event }));

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ export class IgxGridNavigationService {
136136
this.activeNode = null;
137137
return;
138138
}
139-
if (!this.activeNode || !Object.keys(this.activeNode).length || this.activeNode.row < 0 || this.activeNode.row > gridRows - 1) {
139+
if ((!this.activeNode || !Object.keys(this.activeNode).length || this.activeNode.row < 0 || this.activeNode.row > gridRows - 1) &&
140+
this.grid.selectionService.isInMap(this.lastActiveNode)) {
140141
const hasLastActiveNode = Object.keys(this.lastActiveNode).length;
141142
const shouldClearSelection = hasLastActiveNode && (this.lastActiveNode.row < 0 || this.lastActiveNode.row > gridRows - 1);
142143
this.setActiveNode(this.lastActiveNode.row >= 0 && this.lastActiveNode.row < gridRows ?

projects/igniteui-angular/src/lib/grids/grid/grid-cell-selection.spec.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ describe('IgxGrid - Cell selection #grid', () => {
341341
];
342342
const expectedData2 = [
343343
{ ID: 475, ParentID: 147, Name: 'Michael Langdon' },
344-
{ ID: 957, ParentID: 147 },
344+
{ ID: 957 },
345345
{ ID: 317, ParentID: 147 }
346346
];
347347

@@ -362,18 +362,17 @@ describe('IgxGrid - Cell selection #grid', () => {
362362
GridSelectionFunctions.verifyCellsRegionSelected(grid, 0, 2, 0, 1);
363363
GridSelectionFunctions.verifyCellSelected(thirdCell);
364364

365-
// Click on a cell in the region and verify it is not changed
365+
// Click on a cell in the region and verify it is deselected
366366
let cell = grid.gridAPI.get_cell_by_index(1, 'ParentID');
367367
UIInteractions.simulateClickAndSelectEvent(cell, false, true);
368368
fix.detectChanges();
369369

370-
GridSelectionFunctions.verifyCellsRegionSelected(grid, 0, 2, 0, 1);
371-
GridSelectionFunctions.verifyCellSelected(thirdCell);
370+
GridSelectionFunctions.verifyCellsRegionSelected(grid, 0, 0, 0, 2);
371+
GridSelectionFunctions.verifyCellsRegionSelected(grid, 2, 2, 0, 1);
372+
GridSelectionFunctions.verifyCellSelected(cell, false);
373+
GridSelectionFunctions.verifyCellSelected(grid.gridAPI.get_cell_by_index(1, 'ID'), true);
372374
expect(selectionChangeSpy).toHaveBeenCalledTimes(1);
373375
expect(grid.getSelectedData()).toEqual(expectedData2);
374-
GridSelectionFunctions.verifySelectedRange(grid, 0, 2, 0, 1, 0, 3);
375-
GridSelectionFunctions.verifySelectedRange(grid, 0, 0, 2, 2, 1, 3);
376-
GridSelectionFunctions.verifySelectedRange(grid, 1, 1, 1, 1, 2, 3);
377376

378377
// Click on a cell without holding Ctrl
379378
cell = grid.gridAPI.get_cell_by_index(0, 'ID');

projects/igniteui-angular/src/lib/grids/selection/selection.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export class IgxGridSelectionService {
333333
return true;
334334
}
335335

336-
if (this.pointerEventInGridBody) {
336+
if (this.pointerEventInGridBody && this.isActiveNode(node)) {
337337
this.add(node);
338338
}
339339
return false;

0 commit comments

Comments
 (0)