File tree Expand file tree Collapse file tree 1 file changed +6
-9
lines changed
src/components-examples/cdk/tree/cdk-tree-flat-level-accessor Expand file tree Collapse file tree 1 file changed +6
-9
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ export class CdkTreeFlatLevelAccessorExample {
2020 getParentNode ( node : FlatFoodNode ) {
2121 const nodeIndex = FLAT_DATA . indexOf ( node ) ;
2222
23+ // Determine the node's parent by finding the first preceding node that's
24+ // one level shallower.
2325 for ( let i = nodeIndex - 1 ; i >= 0 ; i -- ) {
2426 if ( FLAT_DATA [ i ] . level === node . level - 1 ) {
2527 return FLAT_DATA [ i ] ;
@@ -29,14 +31,9 @@ export class CdkTreeFlatLevelAccessorExample {
2931 return null ;
3032 }
3133
32- shouldRender ( node : FlatFoodNode ) {
33- let parent = this . getParentNode ( node ) ;
34- while ( parent ) {
35- if ( ! parent . isExpanded ) {
36- return false ;
37- }
38- parent = this . getParentNode ( parent ) ;
39- }
40- return true ;
34+ shouldRender ( node : FlatFoodNode ) : boolean {
35+ // This node should render if it is a root node or if all of its ancestors are expanded.
36+ const parent = this . getParentNode ( node ) ;
37+ return ! parent || ( ! ! parent . isExpanded && this . shouldRender ( parent ) ) ;
4138 }
4239}
You can’t perform that action at this time.
0 commit comments