bug(virtual-scroll): scrollToIndex on viewport while inside cdkVirtualScrollingElement is wrong
- Lenguaje dominante
- TypeScript
- Estrellas
- 25k
- Forks
- 6.8k
- Merge medio
- 1 d 8 h
- PR fusionados (30 d)
- 91
Descripción
### 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
Guía de contribución
Línea de trabajo
Comienza con la implementación del viewport de desplazamiento virtual de CDK y el punto de entrada scrollToIndex; después, compara su comportamiento con measureViewportOffset('top') en la reproducción de StackBlitz proporcionada. Verifica el cambio con los casos regular viewport y cdkVirtualScrollingElement: al desplazarse hasta el elemento 50, debería seleccionarse el elemento 50 en ambas secciones, incluso con el desplazamiento del encabezado de 100px.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- angular, typescript
- Área
- frontend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 64/100