Skip to content

Commit 2df0f42

Browse files
authored
Merge branch 'master' into elevation-schemas
2 parents 0e14814 + f9c0c9a commit 2df0f42

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,14 +455,17 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
455455
const cell = cells[0];
456456
const childContainer = this.grid.nativeElement.parentNode.parentNode;
457457
const scrTop = this.grid.parent.verticalScrollContainer.getVerticalScroll().scrollTop;
458+
const maxScroll = this.grid.parent.verticalScrollContainer.getVerticalScroll().scrollHeight - this.grid.parent.calcHeight;
458459
const dc = childContainer.parentNode.parentNode;
459460
const scrWith = parseInt(dc.style.top, 10);
460-
if (scrTop === 0 || scrWith === 0) {
461+
const parentRowOffset = childContainer.parentNode.offsetTop + this.grid.nativeElement.offsetTop +
462+
scrWith;
463+
if ((scrTop === 0 && parentRowOffset < 0 ) || parentRowOffset === 0 || (scrTop === maxScroll && parentRowOffset > 0)) {
461464
// cell is in view
462465
cell.focus({ preventScroll: true });
463466
} else {
464467
// scroll parent so that cell is in view
465-
this.scrollGrid(this.grid.parent, scrWith, () => cell.focus({ preventScroll: true }));
468+
this.scrollGrid(this.grid.parent, parentRowOffset, () => cell.focus({ preventScroll: true }));
466469
}
467470
}
468471

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ describe('IgxHierarchicalGrid Basic Navigation', () => {
274274
expect(childCell.rowIndex).toBe(0);
275275

276276
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
277-
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1);
277+
const childGridOffset = childGrid.nativeElement.offsetTop;
278+
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1 + childGridOffset);
278279
}));
279280

280281
it('should allow navigating to bottom in child grid when child grid target row moves outside the parent view port.', (async () => {
@@ -349,7 +350,29 @@ describe('IgxHierarchicalGrid Basic Navigation', () => {
349350
expect(childFirstRowCell.rowIndex).toBe(0);
350351

351352
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
352-
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1);
353+
const childGridOffset = childGrid.nativeElement.offsetTop;
354+
expect(currScrTop).toBeLessThanOrEqual(childGrid.rowHeight + 1 + childGridOffset);
355+
}));
356+
357+
it('should scroll top of child grid into view when pressing Ctrl + Arrow Up when cell is selected in it.', (async () => {
358+
hierarchicalGrid.verticalScrollContainer.scrollTo(3);
359+
await wait(100);
360+
fixture.detectChanges();
361+
362+
const childGrid = hierarchicalGrid.hgridAPI.getChildGrids(false)[3];
363+
const childLastRowCell = childGrid.dataRowList.toArray()[9].cells.toArray()[0];
364+
childLastRowCell.nativeElement.focus();
365+
fixture.detectChanges();
366+
childLastRowCell.nativeElement.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowUp', ctrlKey: true }));
367+
await wait(100);
368+
fixture.detectChanges();
369+
const childFirstRowCell = childGrid.dataRowList.toArray()[0].cells.toArray()[0];
370+
expect(childFirstRowCell.selected).toBe(true);
371+
expect(childFirstRowCell.columnIndex).toBe(0);
372+
expect(childFirstRowCell.rowIndex).toBe(0);
373+
374+
const currScrTop = hierarchicalGrid.verticalScrollContainer.getVerticalScroll().scrollTop;
375+
expect(currScrTop).toBeGreaterThanOrEqual(2000);
353376
}));
354377

355378
it('when navigating down from parent into child should scroll child grid to top and start navigation from first row.', (async () => {

0 commit comments

Comments
 (0)