-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(material/tree): update examples on docs pages, add new childrenA…
…ccessor examples (#29752) * docs(mat/tree): add childrenAccessor example for mat-tree flat * fix(mat/tree): fix imports * docs(mat/tree): add childrenAccessor example for nested mat-tree * fix(mat/tree): fix imports * fix(mat/tree): formatting (cherry picked from commit c4ca044)
- Loading branch information
1 parent
f9e1810
commit 724dc2f
Showing
10 changed files
with
194 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
export {TreeDynamicExample} from './tree-dynamic/tree-dynamic-example'; | ||
export {TreeFlatOverviewExample} from './tree-flat-overview/tree-flat-overview-example'; | ||
export {TreeFlatChildAccessorOverviewExample} from './tree-flat-child-accessor-overview/tree-flat-child-accessor-overview-example'; | ||
export {TreeHarnessExample} from './tree-harness/tree-harness-example'; | ||
export {TreeLoadmoreExample} from './tree-loadmore/tree-loadmore-example'; | ||
export {TreeNestedOverviewExample} from './tree-nested-overview/tree-nested-overview-example'; | ||
export {TreeNestedChildAccessorOverviewExample} from './tree-nested-child-accessor-overview/tree-nested-child-accessor-overview-example'; | ||
export {TreeLegacyKeyboardInterfaceExample} from './tree-legacy-keyboard-interface/tree-legacy-keyboard-interface-example'; |
19 changes: 19 additions & 0 deletions
19
...ial/tree/tree-flat-child-accessor-overview/tree-flat-child-accessor-overview-example.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<mat-tree #tree [dataSource]="dataSource" [childrenAccessor]="childrenAccessor"> | ||
<!-- This is the tree node template for leaf nodes --> | ||
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding> | ||
<!-- use a disabled button to provide padding for tree leaf --> | ||
<button mat-icon-button disabled></button> | ||
{{node.name}} | ||
</mat-tree-node> | ||
<!-- This is the tree node template for expandable nodes --> | ||
<mat-tree-node *matTreeNodeDef="let node;when: hasChild" matTreeNodePadding matTreeNodeToggle | ||
[cdkTreeNodeTypeaheadLabel]="node.name"> | ||
<button mat-icon-button matTreeNodeToggle | ||
[attr.aria-label]="'Toggle ' + node.name"> | ||
<mat-icon class="mat-icon-rtl-mirror"> | ||
{{tree.isExpanded(node) ? 'expand_more' : 'chevron_right'}} | ||
</mat-icon> | ||
</button> | ||
{{node.name}} | ||
</mat-tree-node> | ||
</mat-tree> |
51 changes: 51 additions & 0 deletions
51
...erial/tree/tree-flat-child-accessor-overview/tree-flat-child-accessor-overview-example.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {MatTreeModule} from '@angular/material/tree'; | ||
import {MatIconModule} from '@angular/material/icon'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
|
||
/** | ||
* Food data with nested structure. | ||
* Each node has a name and an optional list of children. | ||
*/ | ||
interface FoodNode { | ||
name: string; | ||
children?: FoodNode[]; | ||
} | ||
|
||
const TREE_DATA: FoodNode[] = [ | ||
{ | ||
name: 'Fruit', | ||
children: [{name: 'Apple'}, {name: 'Banana'}, {name: 'Fruit loops'}], | ||
}, | ||
{ | ||
name: 'Vegetables', | ||
children: [ | ||
{ | ||
name: 'Green', | ||
children: [{name: 'Broccoli'}, {name: 'Brussels sprouts'}], | ||
}, | ||
{ | ||
name: 'Orange', | ||
children: [{name: 'Pumpkins'}, {name: 'Carrots'}], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
/** | ||
* @title Tree with flat nodes (childrenAccessor) | ||
*/ | ||
@Component({ | ||
selector: 'tree-flat-child-accessor-overview-example', | ||
templateUrl: 'tree-flat-child-accessor-overview-example.html', | ||
standalone: true, | ||
imports: [MatTreeModule, MatButtonModule, MatIconModule], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TreeFlatChildAccessorOverviewExample { | ||
dataSource = TREE_DATA; | ||
|
||
childrenAccessor = (node: FoodNode) => node.children ?? []; | ||
|
||
hasChild = (_: number, node: FoodNode) => !!node.children && node.children.length > 0; | ||
} |
26 changes: 26 additions & 0 deletions
26
.../tree/tree-nested-child-accessor-overview/tree-nested-child-accessor-overview-example.css
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.example-tree-invisible { | ||
display: none; | ||
} | ||
|
||
.example-tree ul, | ||
.example-tree li { | ||
margin-top: 0; | ||
margin-bottom: 0; | ||
list-style-type: none; | ||
} | ||
|
||
/* | ||
* This padding sets alignment of the nested nodes. | ||
*/ | ||
.example-tree .mat-nested-tree-node div[role=group] { | ||
padding-left: 40px; | ||
} | ||
|
||
/* | ||
* Padding for leaf nodes. | ||
* Leaf nodes need to have padding so as to align with other non-leaf nodes | ||
* under the same parent. | ||
*/ | ||
.example-tree div[role=group] > .mat-tree-node { | ||
padding-left: 40px; | ||
} |
28 changes: 28 additions & 0 deletions
28
...tree/tree-nested-child-accessor-overview/tree-nested-child-accessor-overview-example.html
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<mat-tree #tree [dataSource]="dataSource" [childrenAccessor]="childrenAccessor" class="example-tree"> | ||
<!-- This is the tree node template for leaf nodes --> | ||
<!-- There is inline padding applied to this node using styles. | ||
This padding value depends on the mat-icon-button width. --> | ||
<mat-tree-node *matTreeNodeDef="let node"> | ||
{{node.name}} | ||
</mat-tree-node> | ||
<!-- This is the tree node template for expandable nodes --> | ||
<mat-nested-tree-node | ||
*matTreeNodeDef="let node; when: hasChild" | ||
matTreeNodeToggle [cdkTreeNodeTypeaheadLabel]="node.name"> | ||
<div class="mat-tree-node"> | ||
<button mat-icon-button matTreeNodeToggle | ||
[attr.aria-label]="'Toggle ' + node.name"> | ||
<mat-icon class="mat-icon-rtl-mirror"> | ||
{{tree.isExpanded(node) ? 'expand_more' : 'chevron_right'}} | ||
</mat-icon> | ||
</button> | ||
{{node.name}} | ||
</div> | ||
<!-- There is inline padding applied to this div using styles. | ||
This padding value depends on the mat-icon-button width. --> | ||
<div [class.example-tree-invisible]="!tree.isExpanded(node)" | ||
role="group"> | ||
<ng-container matTreeNodeOutlet></ng-container> | ||
</div> | ||
</mat-nested-tree-node> | ||
</mat-tree> |
52 changes: 52 additions & 0 deletions
52
...l/tree/tree-nested-child-accessor-overview/tree-nested-child-accessor-overview-example.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {ChangeDetectionStrategy, Component} from '@angular/core'; | ||
import {MatTreeModule} from '@angular/material/tree'; | ||
import {MatIconModule} from '@angular/material/icon'; | ||
import {MatButtonModule} from '@angular/material/button'; | ||
|
||
/** | ||
* Food data with nested structure. | ||
* Each node has a name and an optional list of children. | ||
*/ | ||
interface FoodNode { | ||
name: string; | ||
children?: FoodNode[]; | ||
} | ||
|
||
const TREE_DATA: FoodNode[] = [ | ||
{ | ||
name: 'Fruit', | ||
children: [{name: 'Apple'}, {name: 'Banana'}, {name: 'Fruit loops'}], | ||
}, | ||
{ | ||
name: 'Vegetables', | ||
children: [ | ||
{ | ||
name: 'Green', | ||
children: [{name: 'Broccoli'}, {name: 'Brussels sprouts'}], | ||
}, | ||
{ | ||
name: 'Orange', | ||
children: [{name: 'Pumpkins'}, {name: 'Carrots'}], | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
/** | ||
* @title Tree with nested nodes (childrenAccessor) | ||
*/ | ||
@Component({ | ||
selector: 'tree-nested-child-accessor-overview-example', | ||
templateUrl: 'tree-nested-child-accessor-overview-example.html', | ||
styleUrl: 'tree-nested-child-accessor-overview-example.css', | ||
standalone: true, | ||
imports: [MatTreeModule, MatButtonModule, MatIconModule], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class TreeNestedChildAccessorOverviewExample { | ||
childrenAccessor = (node: FoodNode) => node.children ?? []; | ||
|
||
dataSource = TREE_DATA; | ||
|
||
hasChild = (_: number, node: FoodNode) => !!node.children && node.children.length > 0; | ||
} |
This file contains 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
This file contains 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
This file contains 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