Is this a regression?
The previous version in which this bug was not present was
No response
Description
When scrolling by index using scrollToIndex on the viewport it doesn't take into account any content around the viewport when using cdkVirtualScrollingElement.
The logic calculates the offset only based on the itemSize without taking into account the viewport offset.
Reproduction
StackBlitz link: https://stackblitz.com/edit/qmx1v9bc
Steps to reproduce:
- In the
Regular section clicking on the button Scroll to item 50 correctly scrolls to item 50. This is a regular viewport without cdkVirtualScrollingElement.
- In the
With cdkVirtualScrollingElement section clicking on the button Scroll to item 50 (not working) it scrolls to item 48 instead of 50 as there is a 100px header above the viewport while it should scroll to item 50.
- If the button
Scroll to item 50 (fixed) is clicked the scrolling works as expected as I calculate the offset myself using viewport.measureViewportOffset('top') which is missing in scrollToIndex.
Expected Behavior
It should scroll to the correct item when using cdkVirtualScrollingElement
Actual Behavior
It scrolls without taking into account the viewport offset.
Environment
- Angular: 21.2.6
- CDK/Material: 21.1.2
- Browser(s): Chrome 146
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11
Is this a regression?
The previous version in which this bug was not present was
No response
Description
When scrolling by index using
scrollToIndexon the viewport it doesn't take into account any content around the viewport when usingcdkVirtualScrollingElement.The logic calculates the offset only based on the
itemSizewithout taking into account the viewport offset.Reproduction
StackBlitz link: https://stackblitz.com/edit/qmx1v9bc
Steps to reproduce:
Regularsection clicking on the buttonScroll to item 50correctly scrolls to item 50. This is a regular viewport withoutcdkVirtualScrollingElement.With cdkVirtualScrollingElementsection clicking on the buttonScroll to item 50 (not working)it scrolls to item 48 instead of 50 as there is a 100px header above the viewport while it should scroll to item 50.Scroll to item 50 (fixed)is clicked the scrolling works as expected as I calculate the offset myself usingviewport.measureViewportOffset('top')which is missing inscrollToIndex.Expected Behavior
It should scroll to the correct item when using
cdkVirtualScrollingElementActual Behavior
It scrolls without taking into account the viewport offset.
Environment