Skip to content

Commit 042072f

Browse files
authored
fix(grid): fix out of bounds row index when navigating down from last layout row - 20.1.x (#16757)
1 parent f8215a0 commit 042072f

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
355355

356356
private hasNextVerticalPosition(prev = false) {
357357
if ((prev && this.activeNode.row === 0 && (!this.isDataRow(this.activeNode.row) || this.activeNode.layout.rowStart === 1)) ||
358-
(!prev && this.activeNode.row >= this.grid.dataView.length - 1 && this.activeNode.column === this.lastColIndexPerMRLBlock())) {
358+
(!prev && this.activeNode.row >= this.grid.dataView.length - 1 &&
359+
this.activeNode.layout.rowStart === this.lastRowStartPerBlock())) {
359360
return false;
360361
}
361362
return true;

projects/igniteui-angular/src/lib/grids/grid/grid-mrl-keyboard-nav.spec.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { GridFunctions, GRID_MRL_BLOCK } from '../../test-utils/grid-functions.s
1212
import { CellType } from '../common/grid.interface';
1313
import { IgxColumnLayoutComponent } from '../columns/column-layout.component';
1414
import { IGridCellEventArgs, IgxColumnComponent } from '../public_api';
15+
import { IgxGridMRLNavigationService } from '../grid-mrl-navigation.service';
1516

1617
const DEBOUNCE_TIME = 30;
1718
const CELL_CSS_CLASS = '.igx-grid__td';
@@ -297,6 +298,40 @@ describe('IgxGrid Multi Row Layout - Keyboard navigation #grid', () => {
297298
GridFunctions.verifyGridContentActiveDescendant(GridFunctions.getGridContent(fix), cell.nativeElement.id);
298299
});
299300

301+
it('should not return an out of bounds row index when navigating down from the last layout row', () => {
302+
fix.componentInstance.data = SampleTestData.contactInfoDataFull().slice(0, 10);
303+
fix.componentInstance.colGroups = [{
304+
group: 'group1',
305+
columns: [
306+
{ field: 'ID', rowStart: 1, colStart: 1 },
307+
{ field: 'CompanyName', rowStart: 1, colStart: 2 },
308+
{ field: 'ContactName', rowStart: 1, colStart: 3 },
309+
{ field: 'ContactTitle', rowStart: 1, colStart: 4 },
310+
{ field: 'Address', rowStart: 1, colStart: 5 },
311+
{ field: 'City', rowStart: 2, colStart: 1 },
312+
{ field: 'Region', rowStart: 2, colStart: 2 },
313+
{ field: 'PostalCode', rowStart: 2, colStart: 3 },
314+
{ field: 'Phone', rowStart: 2, colStart: 4 },
315+
{ field: 'Fax', rowStart: 2, colStart: 5 }
316+
]
317+
}];
318+
fix.detectChanges();
319+
320+
const grid = fix.componentInstance.grid;
321+
const lastRowIndex = grid.dataView.length - 1;
322+
const navService = grid.navigation as IgxGridMRLNavigationService;
323+
const col = grid.getColumnByName('City');
324+
navService.setActiveNode({
325+
row: lastRowIndex,
326+
column: col.visibleIndex,
327+
layout: navService.layout(col.visibleIndex)
328+
});
329+
330+
const nextPos = navService.getNextVerticalPosition();
331+
expect(nextPos.row).toBe(lastRowIndex);
332+
expect(nextPos.column).toBe(navService.activeNode.column);
333+
});
334+
300335
it('should navigate up correctly', () => {
301336
fix.componentInstance.colGroups = [{
302337
group: 'group1',

0 commit comments

Comments
 (0)