Following the method in the accepted answer to do this with an animation of the child nodes sliding in/out vertically you can use a nested tree. Stackblitz
Add the animation to the component:
@Component({
selector: 'tree-nested-overview-example',
templateUrl: 'tree-nested-overview-example.html',
styleUrls: ['tree-nested-overview-example.css'],
animations:[
trigger('slideVertical', [
state(
'*',
style({
height: 0
})
),
state(
'show',
style({
height: '*'
})
),
transition('* => *', [animate('400ms cubic-bezier(0.25, 0.8, 0.25, 1)')])
])
]
})
Apply the animation to the element containing the child nodes:
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild">
<li>
<div class="mat-tree-node">
<button mat-icon-button matTreeNodeToggle
[attr.aria-label]="'toggle ' + node.name">
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
{{node.name}}
</div>
<ul [@slideVertical]="treeControl.isExpanded(node) ? 'show' : null">
<ng-container matTreeNodeOutlet></ng-container>
</ul>
</li>
</mat-nested-tree-node>
Hide the overflow on the element:
.example-tree ul {
overflow: hidden;
}