Skip to content

Commit 713a7ff

Browse files
committed
chore(*): fix navigation behavior
1 parent e5cbaf8 commit 713a7ff

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy, CellT
10731073
}
10741074
this.selectionService.primaryButton = true;
10751075
if (this.cellSelectionMode === GridSelectionMode.multiple && this.selectionService.activeElement) {
1076-
if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey) {
1076+
if (this.selectionService.isInMap(this.selectionService.activeElement) && (event as any)?.ctrlKey && !(event as any)?.shiftKey) {
10771077
this.selectionService.remove(this.selectionService.activeElement);
10781078
shouldEmitSelection = true;
10791079
} else {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,6 @@ export class IgxGridNavigationService {
138138
}
139139
if (!this.activeNode || !Object.keys(this.activeNode).length || this.activeNode.row < 0 || this.activeNode.row > gridRows - 1) {
140140
const hasLastActiveNode = Object.keys(this.lastActiveNode).length;
141-
if (hasLastActiveNode && this.grid.cellSelection !== GridSelectionMode.none && !this.grid.selectionService.isInMap(this.lastActiveNode)) {
142-
return;
143-
}
144141
const shouldClearSelection = hasLastActiveNode && (this.lastActiveNode.row < 0 || this.lastActiveNode.row > gridRows - 1);
145142
this.setActiveNode(this.lastActiveNode.row >= 0 && this.lastActiveNode.row < gridRows ?
146143
this.firstVisibleNode(this.lastActiveNode.row) : this.firstVisibleNode());
@@ -151,6 +148,9 @@ export class IgxGridNavigationService {
151148
this.grid.cdr.detectChanges();
152149
});
153150
} else {
151+
if (hasLastActiveNode && !this.grid.selectionService.selected(this.lastActiveNode)) {
152+
return;
153+
}
154154
const range = {
155155
rowStart: this.activeNode.row, rowEnd: this.activeNode.row,
156156
columnStart: this.activeNode.column, columnEnd: this.activeNode.column

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,34 @@ describe('IgxGrid - Cell selection #grid', () => {
225225
GridSelectionFunctions.verifySelectedRange(grid, 0, 0, 0, 0, 2, 3);
226226
});
227227

228+
it('Should be able to select cells correctly when focus is returned to the grid', async() => {
229+
const firstCell = grid.gridAPI.get_cell_by_index(1, 'ParentID');
230+
const secondCell = grid.gridAPI.get_cell_by_index(2, 'Name');
231+
232+
UIInteractions.simulateClickAndSelectEvent(firstCell);
233+
fix.detectChanges();
234+
235+
GridSelectionFunctions.verifyCellSelected(firstCell);
236+
expect(grid.selectedCells.length).toBe(1);
237+
238+
UIInteractions.simulateClickAndSelectEvent(firstCell, false, true);
239+
fix.detectChanges();
240+
241+
expect(grid.selectedCells.length).toBe(0);
242+
243+
grid.navigation.lastActiveNode = grid.navigation.activeNode;
244+
grid.navigation.activeNode = null;
245+
fix.detectChanges();
246+
grid.tbody.nativeElement.focus();
247+
fix.detectChanges();
248+
249+
UIInteractions.simulateClickAndSelectEvent(secondCell, false, true);
250+
fix.detectChanges();
251+
GridSelectionFunctions.verifyCellSelected(firstCell, false);
252+
GridSelectionFunctions.verifyCellSelected(secondCell, true);
253+
expect(grid.selectedCells.length).toBe(1);
254+
});
255+
228256
it('Should be able to select range when click on a cell and hold Shift key and click on another Cell', () => {
229257
const firstCell = grid.gridAPI.get_cell_by_index(3, 'HireDate');
230258
const secondCell = grid.gridAPI.get_cell_by_index(1, 'ID');

0 commit comments

Comments
 (0)