Trees display hierarchical information in a nested, expandable format.
Trees help users navigate complex structures by organizing content into parent and child relationships. They're commonly used for navigation menus, file browsers, and category lists. For flat lists without nested content, use the navigation list instead.
To use tree in a standalone component, import DAFF_TREE_COMPONENTS directly into your custom component:
import { DAFF_TREE_COMPONENTS } from '@daffodil/design/tree';
@Component({
selector: 'custom-component',
templateUrl: './custom-component.component.html',
imports: [
DAFF_TREE_COMPONENTS,
],
})
export class CustomComponent {}
To use tree in a module, import DaffTreeModule into your custom module:
import { NgModule } from '@angular/core';
import { DaffTreeModule } from '@daffodil/design/tree';
import { CustomComponent } from './custom.component';
@NgModule({
declarations: [
CustomComponent,
],
exports: [
CustomComponent,
],
imports: [
DaffTreeModule,
],
})
export class CustomComponentModule { }
Warning
This method is deprecated. It's recommended to update all custom components to standalone.
A tree consists of the following parts:
<daff-tree>: The main wrapper that holds the tree and accepts your data.
Define how each tree item looks:
#daffTreeItemWithChildrenTpl: For items that can expand to show children. Click handling and icons are added automatically.#daffTreeItemTpl: For items at the end of a branch with no children.[daffTreeItem]: Added to links or buttons inside your templates to connect them to the tree.
<daff-tree [tree]="treeData">
<ng-template #daffTreeItemWithChildrenTpl let-node>
<button daffTreeItem [node]="node">{{ node.title }}</button>
</ng-template>
<ng-template #daffTreeItemTpl let-node>
<a daffTreeItem [node]="node" [routerLink]="node.url">{{ node.title }}</a>
</ng-template>
</daff-tree>
The tree follows the disclosure navigation menu pattern rather than the tree view pattern.
id automatically assigned to each tree itemaria-expanded indicating whether a parent item is open or closed<a>) for navigation and buttons (<button>) for expanding sections