Skip to content

bug(cdk/scrolling): scrollToIndex doesn't account for content before (when used with scrollWindow) #26538

Open
@Dador

Description

@Dador

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

scrollToIndex doesn't account for content before scrollable (when used with scrollWindow).
Probably it should use measureViewportOffset or similar method to account for it.

Reproduction

Steps to reproduce:

  1. Open https://stackblitz.com/edit/angular-ewgqzt?file=src/app/cdk-virtual-scroll-window-scrolling-example.ts
  2. Click on button Scroll to index #1

Expected Behavior

Viewport should be scrolled so Scroll to index #1, so is the first element.

Actual Behavior

Viewport is scrolled but "Content before" is the first element. It's off by "content before" height.

Environment

  • Angular: 15
  • CDK/Material: 15.1.2
  • Browser(s): Chrome 108
  • Operating System (e.g. Windows, macOS, Ubuntu): macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/scrolling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions