Skip to content

Commit ac801f6

Browse files
MKirovaMKirova
authored andcommitted
chore(*): Adjust scroll position after sizes change.
1 parent e76211d commit ac801f6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,14 +1413,17 @@ export class IgxForOfDirective<T> implements OnInit, OnChanges, DoCheck, OnDestr
14131413
}
14141414

14151415

1416-
private _adjustScrollPositionAfterSizeChange(sizeDiff) {
1416+
protected _adjustScrollPositionAfterSizeChange(sizeDiff) {
14171417
// if data has been changed while container is scrolled
14181418
// should update scroll top/left according to change so that same startIndex is in view
14191419
if (Math.abs(sizeDiff) > 0 && this.scrollPosition > 0) {
14201420
this.recalcUpdateSizes();
14211421
const offset = parseInt(this.dc.instance._viewContainer.element.nativeElement.style.top, 10);
14221422
const newSize = this.sizesCache[this.state.startIndex] - offset;
1423-
this.scrollPosition = newSize === this.scrollPosition ? newSize + 1 : newSize;
1423+
this.scrollPosition = newSize;
1424+
if (this.scrollPosition !== newSize) {
1425+
this.scrollComponent.scrollAmount = newSize;
1426+
}
14241427
}
14251428
}
14261429

@@ -1575,8 +1578,11 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
15751578
}
15761579
this.syncService.setMaster(this);
15771580
this.igxForContainerSize = args.containerSize;
1578-
this._updateSizeCache(changes);
1581+
const sizeDiff = this._updateSizeCache(changes);
15791582
this._applyChanges();
1583+
if (sizeDiff) {
1584+
this._adjustScrollPositionAfterSizeChange(sizeDiff);
1585+
}
15801586
this._updateScrollOffset();
15811587
this.dataChanged.emit();
15821588
}
@@ -1681,6 +1687,7 @@ export class IgxGridForOfDirective<T> extends IgxForOfDirective<T> implements On
16811687
}
16821688
});
16831689
}
1690+
return diff;
16841691
}
16851692

16861693
protected handleCacheChanges(changes: IterableChanges<T>) {

0 commit comments

Comments
 (0)