bug(virtual-scroll): scrollToIndex on viewport while inside cdkVirtualScrollingElement is wrong
- Langage dominant
- TypeScript
- Étoiles
- 25k
- Forks
- 6.8k
- Merge moyen
- 1 j 8 h
- PR mergées (30 j)
- 91
Description
### Is this a regression?
- [ ] Yes, this behavior used to work in the previous version
### 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:
1. In the `Regular` section clicking on the button `Scroll to item 50` correctly scrolls to item 50. This is a regular viewport without `cdkVirtualScrollingElement`.
2. 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.
3. 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
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Commencez par l’implémentation du viewport de défilement virtuel de CDK et le point d’entrée scrollToIndex, puis comparez son comportement avec measureViewportOffset('top') dans la reproduction StackBlitz fournie. Vérifiez la modification avec les cas regular viewport et cdkVirtualScrollingElement : faire défiler jusqu’à l’élément 50 doit sélectionner l’élément 50 dans les deux sections, y compris avec le décalage d’en-tête de 100px.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- angular, typescript
- Domaine
- frontend
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Plutôt claire
- Accessibilité débutants
- 64/100