Skip to content

Commit 2e363ea

Browse files
committed
refactor(aria/tree): slight improvements to tree example
1 parent cade2ce commit 2e363ea

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

src/aria/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class Tree<V> {
184184
});
185185

186186
afterRenderEffect(() => {
187-
if (!this._hasFocused()) {
187+
if (!this._hasFocused() && !this._pattern.treeBehavior.inputs.activeItem()) {
188188
this._pattern.setDefaultState();
189189
}
190190
});

src/components-examples/aria/simple-combobox/simple-combobox-examples.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@
166166
align-items: center;
167167
gap: 1rem;
168168
padding: 0.3rem 1rem;
169+
border-radius: var(--mat-sys-corner-extra-small);
170+
}
171+
172+
.example-tree-item[data-active='true'] {
173+
background-color: color-mix(in srgb, var(--mat-sys-primary) 10%, transparent);
174+
outline: 2px solid var(--mat-sys-primary);
169175
}
170176

171177
li[aria-expanded='false']+ul[role='group'] {

src/components-examples/aria/simple-combobox/simple-combobox-tree/simple-combobox-tree-example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
<ng-template
1515
[cdkConnectedOverlay]="{origin, usePopover: 'inline', matchWidth: true}"
16-
[cdkConnectedOverlayOpen]="true"
16+
[cdkConnectedOverlayOpen]="popupExpanded()"
1717
[cdkConnectedOverlayDisableClose]="true"
1818
>
1919
<ng-template ngComboboxPopup [combobox]="combobox" popupType="tree">

src/components-examples/aria/simple-combobox/simple-combobox-tree/simple-combobox-tree-example.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {Combobox, ComboboxPopup, ComboboxWidget} from '@angular/aria/simple-combobox';
1010
import {Tree, TreeItem, TreeItemGroup} from '@angular/aria/tree';
11-
import {Component, computed, signal, viewChild} from '@angular/core';
11+
import {Component, afterRenderEffect, computed, signal, viewChild} from '@angular/core';
1212
import {NgTemplateOutlet} from '@angular/common';
1313
import {OverlayModule} from '@angular/cdk/overlay';
1414

@@ -43,8 +43,16 @@ export class SimpleComboboxTreeExample {
4343

4444
readonly dataSource = signal(FOOD_DATA);
4545

46+
constructor() {
47+
afterRenderEffect(() => {
48+
if (this.popupExpanded()) {
49+
this.tree()?.scrollActiveItemIntoView();
50+
}
51+
});
52+
}
53+
4654
filteredGroups = computed(() => {
47-
const search = this.searchString().toLowerCase();
55+
const search = this.searchString().trim().toLowerCase();
4856
const data = this.dataSource();
4957

5058
if (!search) {
@@ -61,7 +69,7 @@ export class SimpleComboboxTreeExample {
6169
return {
6270
...node,
6371
children,
64-
expanded: children && children.length > 0,
72+
expanded: children && children.length > 0 ? true : node.expanded,
6573
};
6674
}
6775

0 commit comments

Comments
 (0)