Skip to content

Commit 6e2c112

Browse files
committed
fix(kb-nav): remove activeNode dependence of performing scroll
remove activeNode dependence of performing scroll methods Closes #6747
1 parent ca36aeb commit 6e2c112

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

projects/igniteui-angular/src/lib/grids/grid-base.directive.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5584,10 +5584,11 @@ export class IgxGridBaseDirective extends DisplayDensityBase implements
55845584
if (this.dataView.slice(rowIndex, rowIndex + 1).find(rec => rec.expression || rec.childGridsData)) {
55855585
visibleColIndex = -1;
55865586
}
5587-
const shouldScrollVertically = this.navigation.shouldPerformVerticalScroll(rowIndex);
5587+
const shouldScrollVertically = this.navigation.shouldPerformVerticalScroll(rowIndex, visibleColIndex);
55885588
const shouldScrollHorizontally = this.navigation.shouldPerformHorizontalScroll(visibleColIndex, rowIndex);
55895589
if (shouldScrollVertically) {
5590-
this.navigation.performVerticalScrollToCell(rowIndex, () => { this.navigateTo(rowIndex, visibleColIndex, cb); });
5590+
this.navigation.performVerticalScrollToCell(rowIndex, visibleColIndex,
5591+
() => { this.navigateTo(rowIndex, visibleColIndex, cb); });
55915592
} else if (shouldScrollHorizontally) {
55925593
this.navigation.performHorizontalScrollToCell(visibleColIndex, () => { this.navigateTo(rowIndex, visibleColIndex, cb); });
55935594
} else {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
7373
return true;
7474
}
7575

76-
public shouldPerformVerticalScroll(targetRowIndex: number): boolean {
77-
if (!super.shouldPerformVerticalScroll(targetRowIndex)) { return false; }
76+
public shouldPerformVerticalScroll(targetRowIndex: number, visibleColIndex: number): boolean {
77+
if (!super.shouldPerformVerticalScroll(targetRowIndex, visibleColIndex)) { return false; }
7878

7979
const targetRow = super.getRowElementByIndex(targetRowIndex);
8080
const containerHeight = this.grid.calcHeight ? Math.ceil(this.grid.calcHeight) : 0;
81-
const scrollPos = this.getVerticalScrollPositions(targetRowIndex, this.activeNode.column);
81+
const scrollPos = this.getVerticalScrollPositions(targetRowIndex, visibleColIndex);
8282
return (!targetRow || targetRow.offsetTop + scrollPos.topOffset < Math.abs(this.containerTopOffset)
8383
|| containerHeight && containerHeight < scrollPos.rowBottom - Math.ceil(this.scrollTop));
8484
}
@@ -140,12 +140,12 @@ export class IgxGridMRLNavigationService extends IgxGridNavigationService {
140140
});
141141
}
142142

143-
public performVerticalScrollToCell(rowIndex: number, cb?: () => void) {
144-
const children = this.parentByChildIndex(this.activeNode.column || 0).children;
145-
if (!super.isDataRow(rowIndex) || children.length < 2) { return super.performVerticalScrollToCell(rowIndex, cb); }
143+
public performVerticalScrollToCell(rowIndex: number, visibleColIndex: number, cb?: () => void) {
144+
const children = this.parentByChildIndex(visibleColIndex || 0).children;
145+
if (!super.isDataRow(rowIndex) || children.length < 2) { return super.performVerticalScrollToCell(rowIndex, visibleColIndex, cb); }
146146

147147
const containerHeight = this.grid.calcHeight ? Math.ceil(this.grid.calcHeight) : 0;
148-
const pos = this.getVerticalScrollPositions(rowIndex, this.activeNode.column);
148+
const pos = this.getVerticalScrollPositions(rowIndex, visibleColIndex);
149149
const row = super.getRowElementByIndex(rowIndex);
150150
if ((this.scrollTop > pos.rowTop) && (!row || row.offsetTop + pos.topOffset < Math.abs(this.containerTopOffset))) {
151151
pos.topOffset === 0 ? this.grid.verticalScrollContainer.scrollTo(rowIndex) :

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,21 +313,21 @@ export class IgxGridNavigationService {
313313
return row.expression || row.detailsData ? false : !this.isColumnFullyVisible(visibleColIndex);
314314
}
315315

316-
public shouldPerformVerticalScroll(targetRowIndex: number): boolean {
316+
public shouldPerformVerticalScroll(targetRowIndex: number, visibleColIndex: number): boolean {
317317
const targetRow = this.getRowElementByIndex(targetRowIndex);
318318
const rowHeight = this.grid.verticalScrollContainer.getSizeAt(targetRowIndex);
319319
const containerHeight = this.grid.calcHeight ? Math.ceil(this.grid.calcHeight) : 0;
320320
const endTopOffset = targetRow ? targetRow.offsetTop + rowHeight + this.containerTopOffset : containerHeight + rowHeight;
321321
return !targetRow || targetRow.offsetTop < Math.abs(this.containerTopOffset)
322-
|| containerHeight && containerHeight < endTopOffset;
322+
|| containerHeight && containerHeight < endTopOffset;
323323
}
324324

325325
public navigateInBody(rowIndex, visibleColIndex, cb: Function = null): void {
326326
if (!this.isValidPosition(rowIndex, visibleColIndex) || this.isActiveNode(rowIndex, visibleColIndex)) { return; }
327327
this.grid.navigateTo(this.activeNode.row = rowIndex, this.activeNode.column = visibleColIndex, cb);
328328
}
329329

330-
public performVerticalScrollToCell(rowIndex: number, cb?: () => void) {
330+
public performVerticalScrollToCell(rowIndex: number, visibleColIndex = -1, cb?: () => void) {
331331
this.grid.verticalScrollContainer.scrollTo(rowIndex);
332332
this.grid.verticalScrollContainer.onChunkLoad
333333
.pipe(first()).subscribe(() => {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
8989
super.navigateInBody(rowIndex, visibleColIndex, cb);
9090
}
9191

92-
public shouldPerformVerticalScroll(index, isNext?) {
92+
public shouldPerformVerticalScroll(index, visibleColumnIndex = -1, isNext?) {
9393
const targetRec = this.grid.dataView[index];
9494
if (this.grid.isChildGridRecord(targetRec)) {
9595
const scrollAmount = this.grid.verticalScrollContainer.getScrollForIndex(index, !isNext);
9696
const currScroll = this.grid.verticalScrollContainer.getScroll().scrollTop;
9797
const shouldScroll = !isNext ? scrollAmount > currScroll : currScroll < scrollAmount;
9898
return shouldScroll;
9999
} else {
100-
return super.shouldPerformVerticalScroll(index);
100+
return super.shouldPerformVerticalScroll(index, visibleColumnIndex);
101101
}
102102
}
103103

@@ -130,9 +130,9 @@ export class IgxHierarchicalGridNavigationService extends IgxGridNavigationServi
130130
* @param cb Optional.Callback function called when operation is complete.
131131
*/
132132
protected _handleScrollInChild(rowIndex: number, isNext?: boolean, cb?: Function) {
133-
const shouldScroll = this.shouldPerformVerticalScroll(rowIndex, isNext);
133+
const shouldScroll = this.shouldPerformVerticalScroll(rowIndex, -1, isNext);
134134
if (shouldScroll) {
135-
this.grid.navigation.performVerticalScrollToCell(rowIndex, () => {
135+
this.grid.navigation.performVerticalScrollToCell(rowIndex, -1, () => {
136136
this.positionInParent(rowIndex, isNext, cb);
137137
});
138138
} else {

0 commit comments

Comments
 (0)