Skip to content

Commit 2aeaca0

Browse files
authored
Merge pull request #7346 from IgniteUI/nrobakova/fix-issue-7345
Set navigation.activeNode when call activate method
2 parents 12e300b + 9c90789 commit 2aeaca0

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
763763
return;
764764
}
765765
this.selectionService.pointerDown(this.selectionNode, event.shiftKey, event.ctrlKey);
766-
this.grid.navigation.activeNode = {row: this.rowIndex, column: this.visibleColumnIndex, layout: this.selectionNode.layout };
767766
this.activate(event);
768767
}
769768

@@ -818,7 +817,6 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
818817
@HostListener('click', ['$event'])
819818
public onClick(event: MouseEvent) {
820819
if (this.cellSelectionMode !== GridSelectionMode.multiple) {
821-
this.grid.navigation.activeNode = this.selectionNode;
822820
this.activate(event);
823821
}
824822
this.grid.onCellClick.emit({
@@ -845,6 +843,14 @@ export class IgxGridCellComponent implements OnInit, OnChanges, OnDestroy {
845843
*/
846844
public activate(event: FocusEvent | KeyboardEvent) {
847845
const node = this.selectionNode;
846+
847+
if (this.grid.navigation.activeNode) {
848+
Object.assign(this.grid.navigation.activeNode, {row: this.rowIndex, column: this.visibleColumnIndex});
849+
} else {
850+
const layout = this.column.columnLayoutChild ? this.grid.navigation.layout(this.visibleColumnIndex) : null;
851+
this.grid.navigation.activeNode = { row: this.rowIndex, column: this.visibleColumnIndex, layout: layout };
852+
}
853+
848854
const shouldEmitSelection = !this.selectionService.isActiveNode(node);
849855

850856
if (this.selectionService.primaryButton) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
284284
return column.rowEnd && column.rowEnd - column.rowStart ? column.rowStart + column.rowEnd - column.rowStart : column.rowStart + 1;
285285
}
286286

287-
private layout(visibleIndex) {
287+
/**
288+
* @hidden
289+
* @internal
290+
*/
291+
public layout(visibleIndex) {
288292
const column = this.grid.getColumnByVisibleIndex(visibleIndex);
289293
return {colStart: column.colStart, rowStart: column.rowStart,
290294
colEnd: column.colEnd, rowEnd: column.rowEnd, columnVisibleIndex: column.visibleIndex };

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
207207

208208
const cell = grid.getCellByColumn(0, 'col0');
209209
expect(cell).toBeDefined();
210-
expect(cell.active).toBeTruthy();
211-
expect(cell.selected).toBeTruthy();
210+
GridSelectionFunctions.verifyCellActive(cell);
211+
GridSelectionFunctions.verifyCellSelected(cell);
212212
});
213213

214214
it('should allow navigating down', async () => {
@@ -566,10 +566,10 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
566566
await wait(200);
567567
fix.detectChanges();
568568

569-
570569
const target = grid.getCellByColumn(15, '1');
571570
expect(target).toBeDefined();
572-
expect(target.selected).toBeTruthy();
571+
GridSelectionFunctions.verifyCellSelected(target);
572+
GridSelectionFunctions.verifyCellActive(target);
573573
});
574574

575575
it('Custom KB navigation: should be able to scroll horizontally and vertically to a cell in the grid', async () => {
@@ -588,7 +588,8 @@ describe('IgxGrid - Keyboard navigation #grid', () => {
588588

589589
const target = grid.getCellByColumn(50, '50');
590590
expect(target).toBeDefined();
591-
expect(target.selected).toBeTruthy();
591+
GridSelectionFunctions.verifyCellSelected(target);
592+
GridSelectionFunctions.verifyCellActive(target);
592593
});
593594

594595
it('Custom KB navigation: onGridKeydown should be emitted', async () => {

projects/igniteui-angular/src/lib/test-utils/grid-functions.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { IgxGridExpandableCellComponent } from '../grids/grid/expandable-cell.co
2121

2222
const SUMMARY_LABEL_CLASS = '.igx-grid-summary__label';
2323
const SUMMARY_ROW = 'igx-grid-summary-row';
24-
const CELL_ACTIVE_CSS_CLASS = 'igx-grid-summary--active';
24+
const SUMMARY_CELL_ACTIVE_CSS_CLASS = 'igx-grid-summary--active';
2525
const FILTER_UI_CELL = 'igx-grid-filtering-cell';
2626
const FILTER_UI_ROW = 'igx-grid-filtering-row';
2727
const FILTER_UI_CONNECTOR = 'igx-filtering-chips__connector';
@@ -46,6 +46,7 @@ const ACTIVE_GROUP_ROW_CLASS = 'igx-grid__group-row--active';
4646
const ACTIVE_HEADER_CLASS = 'igx-grid__th--active';
4747
const GROUP_ROW_CLASS = 'igx-grid-groupby-row';
4848
const CELL_SELECTED_CSS_CLASS = 'igx-grid__td--selected';
49+
const CELL_ACTIVE_CSS_CLASS = 'igx-grid__td--active';
4950
const ROW_DIV_SELECTION_CHECKBOX_CSS_CLASS = 'igx-grid__cbx-selection';
5051
const ROW_SELECTION_CSS_CLASS = 'igx-grid__tr--selected';
5152
const HEADER_ROW_CSS_CLASS = '.igx-grid__thead';
@@ -2045,7 +2046,7 @@ export class GridSummaryFunctions {
20452046
const summaryRow = typeof row === 'number' ?
20462047
GridSummaryFunctions.getSummaryRowByDataRowIndex(fix, row) : row;
20472048
const summ = GridSummaryFunctions.getSummaryCellByVisibleIndex(summaryRow, cellIndex);
2048-
const hasClass = summ.nativeElement.classList.contains(CELL_ACTIVE_CSS_CLASS);
2049+
const hasClass = summ.nativeElement.classList.contains(SUMMARY_CELL_ACTIVE_CSS_CLASS);
20492050
expect(hasClass === active).toBeTruthy();
20502051
}
20512052

@@ -2132,6 +2133,11 @@ export class GridSelectionFunctions {
21322133
expect(cell.nativeElement.classList.contains(CELL_SELECTED_CSS_CLASS)).toBe(selected);
21332134
}
21342135

2136+
public static verifyCellActive(cell, active = true) {
2137+
expect(cell.active).toBe(active);
2138+
expect(cell.nativeElement.classList.contains(CELL_ACTIVE_CSS_CLASS)).toBe(active);
2139+
}
2140+
21352141
// Check the grid selected cell and cell in in the onSelection function
21362142
public static verifyGridCellSelected(fix, cell: IgxGridCellComponent) {
21372143
const selectedCellFromGrid = cell.grid.selectedCells[0];

0 commit comments

Comments
 (0)