feat(cdk/scrolling): ScrollToIndexIfNeeded function
- Dominant language
- TypeScript
- Stars
- 25k
- Forks
- 6.8k
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 91
Description
#### Feature Description
We have `scrollToIndex` function on `CdkVirtualScrollViewport`. But we cannot determine whenever an index is or is not withing **visible** viewport.
```ts
const viewPort: CdkVirtualScrollViewport;
scrollToIndex(index: number): void {
const range = viewPort.getRenderedRange();
if (range.start > index || range.end < index) {
// Scroll is 100% needed.
viewPort.scrollToIndex(index, 'auto');
} else {
// The index is within range, but not necessarily within visible viewport!
// From my testing I have +-8 items above and bellow at the time
}
}
```
#### Use Case
It would enable scrolling to an item if only needed.
#### Note
If there was `CdkVirtualScrollViewport.getVisibleRange`, we could even scroll our desired element to the middle of the viewport!
Contributor guide
Research direction
Start with CdkVirtualScrollViewport, especially the existing scrollToIndex and getRenderedRange entry points. Determine how a visible range could be exposed or used to avoid unnecessary scrolling, including the requested middle-of-viewport use case. Done means the viewport can scroll to an index only when it is outside the visible viewport.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, typescript
- Domain
- frontend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100