Skip to content

Commit 258aa9b

Browse files
MayaKirovaChronosSF
authored andcommitted
fix(igxFor): Resetting scroll position cache in case scrollbar size i… (#5351)
* fix(igxFor): Resetting scroll position cache in case scrollbar size is changes so that it no longer shows scrollbar. * chore(*): Fixing whitespaces. * chore(*): Additional fix in case container size is string.
1 parent ea7c2b0 commit 258aa9b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,19 +1086,21 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
10861086

10871087
protected _recalcScrollBarSize() {
10881088
const count = this.isRemote ? this.totalItemCount : (this.igxForOf ? this.igxForOf.length : 0);
1089-
const prevNotVirtual = this.dc.instance.notVirtual;
10901089
this.dc.instance.notVirtual = !(this.igxForContainerSize && this.dc && this.state.chunkSize < count);
1091-
if (!prevNotVirtual && prevNotVirtual !== this.dc.instance.notVirtual) {
1092-
this._scrollPosition = 0;
1093-
}
10941090
if (this.igxForScrollOrientation === 'horizontal') {
10951091
const totalWidth = this.igxForContainerSize ? this.initSizesCache(this.igxForOf) : 0;
10961092
this.hScroll.style.width = this.igxForContainerSize + 'px';
10971093
this.hScroll.children[0].style.width = totalWidth + 'px';
1094+
if (totalWidth <= parseInt(this.igxForContainerSize, 10)) {
1095+
this.scrollPosition = 0;
1096+
}
10981097
}
10991098
if (this.igxForScrollOrientation === 'vertical') {
11001099
this.vh.instance.elementRef.nativeElement.style.height = parseInt(this.igxForContainerSize, 10) + 'px';
11011100
this.vh.instance.height = this._calcHeight();
1101+
if (this.vh.instance.height <= parseInt(this.igxForContainerSize, 10)) {
1102+
this.scrollPosition = 0;
1103+
}
11021104
}
11031105
}
11041106

@@ -1126,7 +1128,7 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
11261128
if (prevChunkSize !== this.state.chunkSize) {
11271129
this.onChunkLoad.emit(this.state);
11281130
}
1129-
if (this.sizesCache && this.hScroll && this.scrollPosition !== 0) {
1131+
if (this.sizesCache && this.hScroll) {
11301132
// Updating horizontal chunks and offsets based on the new scrollLeft
11311133
const scrollOffset = this.fixedUpdateAllElements(this.scrollPosition);
11321134
this.dc.instance._viewContainer.element.nativeElement.style.left = -scrollOffset + 'px';

0 commit comments

Comments
 (0)