Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

bug(virtual-scroll): scrollToIndex on viewport while inside cdkVirtualScrollingElement is wrong

Đang mở
#33,063 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
64/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
angular, typescript
Lĩnh vực
frontend

Hướng nghiên cứu

Bắt đầu với phần triển khai viewport cuộn ảo của CDK và entry point scrollToIndex, sau đó so sánh hành vi của nó với measureViewportOffset('top') trong bản tái hiện StackBlitz được cung cấp. Xác minh thay đổi với các trường hợp regular viewport và cdkVirtualScrollingElement: cuộn đến mục 50 phải chọn mục 50 trong cả hai phần, kể cả khi có offset 100px của header.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area: cdk/scrolling gemini-triaged P3
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
Ngôn ngữ chính
TypeScript
Star
25k
Fork
6.8k
Merge trung bình
1 ngày 1 giờ
Pull request đã merge (30 ngày)
84

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của angular/components

Tất cả issue của angular/components

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.