bug(cdk-tree): cdk tree with levelAccessor only renders all nodes and cant render based on the expanded state #30735
Labels
area: cdk/tree
P3
An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Is this a regression?
The previous version in which this bug was not present was
No response
Description
The tree with
levelAccessor
and flat data can only render all nodes, and when I click on thecdkTreeNodeToggle
component, it still only renders all nodes, and does not have the effect of expanding and collapsing nodes.However, when I use tree with
childrenAccessor
and nested data, it will render specific nodes based on the tree expansion.For example, for the follwing node structure:
Demo 1 👇
When I use
levelAccessor
with flat type node data passed in, it will always show the above structure, no matter if I click to collapse parent 1 or parent 2 or not, it will still be the same.Demo 2 👇
When I use
childrenAccessor
with nested node data passed in, it can dynamically render the nodes based on the expanded and collapsed state. For example, when I click to collapse parent 1, the structure of the tree view is re-rendered as:Extra 📝
Although I see that the official demo hides nodes that don't need to be displayed by a combination of
style.display
andshouldRender
.I think this is still a problem. Because in Demo 1 you have to use
style.display
andshouldRender
to render correctly, while in Demo 2 you can render correctly without them.So I think there is a difference in this behaviour that is problematic.
The same problem exists for
TreeControl
, but we can pass only specific node data into the tree'sdataStream
based on the treeControl's record of the node's isExpanded status.Possible problem location 🤔
components/src/cdk/tree/tree.ts
Lines 1093 to 1103 in 538b8bc
The
flattenedNodes
andrenderNodes
are both equal tonodes
,maybe we should create a method likeshouldRender
that determines which nodes should be rendered and assigns them torenderNodes
?Reproduction
see Desciption
Expected Behavior
Correctly render visible nodes in the tree when expanding or collapsing nodes
Actual Behavior
When use
levelAccessor
with flat data, can not render visible nodes in the tree correctly when expanding or collapsing nodes. But usechildrenAccessor
with nested data, correctly.Environment
The text was updated successfully, but these errors were encountered: