Skip to content

Commit d451c18

Browse files
committed
docs(material/tree): make "Load More" tree node a button
in the "Load More" tree demo, fix unable to press "Load More" button when navigating onto it using arrow keys.
1 parent b97d2fc commit d451c18

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.load-more {
2+
border-radius: 10px;
3+
padding-left: 15px;
4+
padding-right: 15px;
5+
cursor: pointer;
6+
}
7+
.load-more:focus {
8+
/*
9+
Display a focus state for the "Load More" button.
10+
0.12 is a common value in Material Design
11+
*/
12+
background: rgba(0, 0, 0, 0.12);
13+
}
14+
.load-more:hover {
15+
/*
16+
Display a focus state for the "Load More" button.
17+
0.04 is a common value in Material Design
18+
*/
19+
background: rgba(0, 0, 0, 0.04);
20+
}

src/components-examples/material/tree/tree-loadmore/tree-loadmore-example.html

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
{{node.item}}
1919
</mat-tree-node>
2020

21-
<mat-tree-node *matTreeNodeDef="let node; when: isLoadMore" matTreeNodeToggle>
22-
<button mat-button (click)="loadMore(node.loadMoreParentItem)"
23-
(keydown)="loadMoreOnEnterOrSpace($event, node.loadMoreParentItem)">
24-
Load more...
25-
</button>
21+
<mat-tree-node class="load-more" *matTreeNodeDef="let node; when: isLoadMore"
22+
role="button" (click)="loadMoreOnClick($event, node)"
23+
(keydown)="loadMoreOnEnterOrSpace($event, node)">
24+
Load more...
2625
</mat-tree-node>
2726
</mat-tree>

src/components-examples/material/tree/tree-loadmore/tree-loadmore-example.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ export class LoadmoreDatabase {
101101
@Component({
102102
selector: 'tree-loadmore-example',
103103
templateUrl: 'tree-loadmore-example.html',
104+
styleUrl: 'tree-loadmore-example.css',
104105
providers: [LoadmoreDatabase],
105106
standalone: true,
106107
imports: [MatTreeModule, MatButtonModule, MatIconModule],
@@ -159,12 +160,18 @@ export class TreeLoadmoreExample {
159160
isLoadMore = (_: number, _nodeData: LoadmoreFlatNode) => _nodeData.item === LOAD_MORE;
160161

161162
/** Load more nodes from data source */
162-
loadMore(item: string) {
163-
this._database.loadMore(item);
163+
loadMoreOnClick(event: MouseEvent, node: LoadmoreFlatNode) {
164+
if (node.loadMoreParentItem) {
165+
// TODO: set focus to an appropriate location
166+
this._database.loadMore(node.loadMoreParentItem);
167+
}
164168
}
165169

166-
loadMoreOnEnterOrSpace(event: KeyboardEvent, item: string) {
167-
if (event.keyCode === ENTER || event.keyCode === SPACE) {
170+
loadMoreOnEnterOrSpace(event: KeyboardEvent, node: LoadmoreFlatNode) {
171+
const item = node.loadMoreParentItem;
172+
173+
if (item && (event.keyCode === ENTER || event.keyCode === SPACE)) {
174+
// TODO: set focus to an appropriate location
168175
this._database.loadMore(item);
169176

170177
// Prevent default behavior so that the tree node doesn't handle the keypress instead of this

0 commit comments

Comments
 (0)