Description
Reproduction
See the example in the official material documentation
https://material.angular.io/cdk/scrolling/overview#cdk-virtual-scroll-append-only
- Scroll down
- Scrolling is delayed and the correct position is only set after a delay
Screen.Recording.2021-09-13.at.15.43.49.mov
Note: This effect becomes even more apparent when the rendering of an item is more expensive!
Expected Behavior
Virtual scrolling with appendOnly
sets the correct position without jumping to the top.
Actual Behavior
The virtual scroll using appendOnly
jumps for a certain time to the top of the scrolling container. After this period of time, the correct scroll position is set.
A possible solution
I was able to solve this issue by implementing a CustomScrollingStrategy that copy-pastes FixedSizeScrollingStrategy and adapts line 171.
- this._viewport.setRenderedContentOffset(this._itemSize * newRange.start);
+ this._viewport.setRenderedContentOffset(0, 'to-start');
I am missing the insights to be able to open a pull request fixing this issue respecting all different use cases of virtual scrolling with and without appendOnly
. So I am open to any kind of help to fix this issue.
Environment
- Angular: 12.2.5
- CDK/Material: 12.2.5
- Browser(s): Chrome
- Operating System (e.g. Windows, macOS, Ubuntu): macOS