angular / angular/components

feat(cdk/scrolling): Scroll functions silently fail if the viewport is not yet fully initialized

Open
#23,716 2 comments 2 reactions 0 assignees View on GitHub
area: cdk/scrolling feature P4
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

#### Feature Description

`cdk-virtual-scroll-viewport`'s `scrollTo...` functions (like `scrollToIndex`) silently fail when the viewport is not yet initialized. Technically the functions are doing nothing wrong from a code standpoint, but since the component is not yet fully initialized, it is empty, so trying to scroll will do nothing meaningful. Sending back an error (or at least logging a warning to the console) if an empty viewport is scrolled would be helpful so that developers know that something went wrong.

This would be mitigated if we had an async option that managed the timing of scroll commands. See [this feature request](https://github.com/angular/components/issues/23715).

#### Use Case

This would improve every use case of the virtual scroller.

Contributor guide

Open the contributing guide

Research direction

Start at the cdk-virtual-scroll-viewport scrollTo... entry points and inspect how initialization and an empty viewport are represented. Confirm with maintainers whether the completed behavior should be an error or a console warning, then add focused coverage showing that scrolling before initialization no longer fails silently.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.