Repository navigation
Conversation
Adds support for rendering the tree inside of a `cdk-virtual-scroll-viewport`. The tree detects the viewport in its host, attaches itself to it and only renders the nodes that are currently in the rendered range. Key pieces: - Injects `CDK_VIRTUAL_SCROLL_VIEWPORT` with `host: true` so that only a viewport in the same host enables the feature. - Forwards `renderedRangeStream` to `viewChange` and slices the flattened nodes to the rendered range before rendering. - Pushes the full flattened list through `_dataStream` so that the viewport knows the total number of items and can size the scrollbar correctly. - Implements `measureRangeSize` so that the `autosize` strategy can measure the rendered nodes. - Scrolls the viewport when keyboard navigation moves the active node outside of the rendered range, and handles arrow/home/end keys at the window edges. - Throws a dev-mode error when virtual scrolling is used with a nested tree, since nested nodes render their children inside the parent and there is no flat list to virtualize. - Adds an internal `_disableVirtualScrolling` opt out, mirroring `CdkTable`.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Desciption
Updates the CDK tree to add support for virtual scrolling. This follows the same approach as the table support added in #32487, adapted for the tree's data model and keyboard navigation.
To enable virtual scrolling for the tree, you need to do two things.
<cdk-virtual-scroll-viewport>around it:The tree detects the viewport in its host, attaches itself to it and only renders the nodes that are currently in the rendered range. No extra imports or inputs are required.
Implementation notes
CDK_VIRTUAL_SCROLL_VIEWPORTwithhost: true, so only a viewport in the same host enables the feature (same a sCdkTable).renderedRangeStreamtoviewChangeand slices the flattened nodes to the rendered range before rendering._dataStreamso the viewport knows the total item count and can size the scrollbar correctly.measureRangeSizeso the autosize strategy can measure rendered nodes._disableVirtualScrollingopt out, mirroringCdkTable.Testing
Related to #10122.