Skip to content

Commit 21a946b

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Additional small fixes related to navigation.
1 parent 8590a00 commit 21a946b

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

projects/igniteui-angular/src/lib/directives/for-of/for_of.directive.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,16 +721,33 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
721721
return scroll;
722722
}
723723

724-
725724
/**
726725
* Returns the index of the element at the specified offset.
727726
* ```typescript
728727
* this.parentVirtDir.getIndexAtScroll(100);
729728
* ```
730729
*/
731-
public getIndexAtScroll(scrollOffset: number) {
730+
public getIndexAtScroll(scrollOffset: number) {
732731
return this.getIndexAt(scrollOffset, this.sizesCache);
733732
}
733+
/**
734+
* Returns whether the target index is outside the view.
735+
* ```typescript
736+
* this.parentVirtDir.isIndexOutsideView(10);
737+
* ```
738+
*/
739+
public isIndexOutsideView(index: number) {
740+
const targetNode = index >= this.state.startIndex && index <= this.state.startIndex + this.state.chunkSize ?
741+
this._embeddedViews.map(view =>
742+
view.rootNodes.find(node => node.nodeType === Node.ELEMENT_NODE) || view.rootNodes[0].nextElementSibling)[index - this.state.startIndex] : null;
743+
const rowHeight = this.getSizeAt(index);
744+
const containerSize = parseInt(this.igxForContainerSize, 10);
745+
const containerOffset = -(this.scrollPosition - this.sizesCache[this.state.startIndex]);
746+
const endTopOffset = targetNode ? targetNode.offsetTop + rowHeight + containerOffset : containerSize + rowHeight;
747+
return !targetNode || targetNode.offsetTop < Math.abs(containerOffset)
748+
|| containerSize && endTopOffset - containerSize > 5;
749+
}
750+
734751

735752
/**
736753
* @hidden

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { IgxGridNavigationService } from '../grid-navigation.service';
22
import { Injectable } from '@angular/core';
33
import { IgxPivotGridComponent } from './pivot-grid.component';
44
import { HEADER_KEYS } from '../../core/utils';
5+
import { IgxGridForOfDirective } from '../../directives/for-of/for_of.directive';
6+
import { first } from 'rxjs/operators';
7+
import { ComboSampleComponent } from 'src/app/combo/combo.sample';
58

69
@Injectable()
710
export class IgxPivotGridNavigationService extends IgxGridNavigationService {
@@ -43,7 +46,7 @@ export class IgxPivotGridNavigationService extends IgxGridNavigationService {
4346
newActiveNode.row = ctrl ? 0 : this.activeNode.row - 1;
4447
}
4548
if ((key.includes('down')) && this.activeNode.row < this.findLastDataRowIndex()) {
46-
newActiveNode.row = ctrl ? this.findLastDataRowIndex() : this.activeNode.row + 1;
49+
newActiveNode.row = ctrl ? verticalContainer.igxForOf.length - 1 : Math.min(this.activeNode.row + 1, verticalContainer.igxForOf.length - 1);
4750
}
4851

4952
if (key.includes('left') || key.includes('right')) {
@@ -59,7 +62,9 @@ export class IgxPivotGridNavigationService extends IgxGridNavigationService {
5962
};
6063
}
6164
this.setActiveNode(newActiveNode);
62-
verticalContainer.scrollTo(newActiveNode.row);
65+
if (verticalContainer.isIndexOutsideView(newActiveNode.row)) {
66+
verticalContainer.scrollTo(newActiveNode.row);
67+
}
6368
} else {
6469
super.handleNavigation(event);
6570
}

projects/igniteui-angular/src/lib/grids/pivot-grid/pivot-grid.component.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,10 @@ export class IgxPivotGridComponent extends IgxGridBaseDirective implements OnIni
10391039

10401040
protected verticalScrollHandler(event) {
10411041
super.verticalScrollHandler(event);
1042-
this.verticalRowDimScrollContainers.forEach(x => x.onScroll(event));
1042+
this.verticalRowDimScrollContainers.forEach(x => {
1043+
x.onScroll(event);
1044+
x.cdr.detectChanges();
1045+
});
10431046
}
10441047

10451048
/**

0 commit comments

Comments
 (0)