Skip to content

Commit 181fcb8

Browse files
committed
refactor(aria/tree): passthrough property accessors directly from patterns
1 parent 40ab03e commit 181fcb8

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/aria/private/tree/tree.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {computed, signal} from '@angular/core';
9+
import {computed, signal, Signal} from '@angular/core';
1010
import {SignalLike, WritableSignalLike} from '../behaviors/signal-like/signal-like';
1111
import {List, ListInputs, ListItem} from '../behaviors/list/list';
1212
import {ExpansionItem, ExpansionControl, ListExpansion} from '../behaviors/expansion/expansion';
@@ -74,13 +74,13 @@ export class TreeItemPattern<V> implements ListItem<V>, ExpansionItem {
7474
readonly selectable: SignalLike<boolean>;
7575

7676
/** The level of the current item in a tree. */
77-
readonly level: SignalLike<number> = computed(() => this.parent().level() + 1);
77+
readonly level: Signal<number> = computed(() => this.parent().level() + 1);
7878

7979
/** Whether this item is currently expanded. */
8080
readonly expanded = computed(() => this.expansion.isExpanded());
8181

8282
/** Whether this item is visible. */
83-
readonly visible: SignalLike<boolean> = computed(
83+
readonly visible: Signal<boolean> = computed(
8484
() => this.parent().expanded() && this.parent().visible(),
8585
);
8686

@@ -97,7 +97,7 @@ export class TreeItemPattern<V> implements ListItem<V>, ExpansionItem {
9797
readonly tabindex = computed(() => this.tree().listBehavior.getItemTabindex(this));
9898

9999
/** Whether the item is selected. */
100-
readonly selected: SignalLike<boolean | undefined> = computed(() => {
100+
readonly selected = computed(() => {
101101
if (this.tree().nav()) {
102102
return undefined;
103103
}
@@ -108,7 +108,7 @@ export class TreeItemPattern<V> implements ListItem<V>, ExpansionItem {
108108
});
109109

110110
/** The current type of this item. */
111-
readonly current: SignalLike<string | undefined> = computed(() => {
111+
readonly current = computed(() => {
112112
if (!this.tree().nav()) {
113113
return undefined;
114114
}

src/aria/tree/tree.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
271271
/** Search term for typeahead. */
272272
readonly searchTerm = computed(() => this.label() ?? this.element().textContent);
273273

274+
/** Whether the item is active. */
275+
active: Signal<boolean>;
276+
274277
/** The tree root. */
275278
readonly tree: Signal<Tree<V>> = computed(() => {
276279
if (this.parent() instanceof Tree) {
@@ -279,25 +282,22 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
279282
return (this.parent() as TreeItemGroup<V>).ownedBy().tree();
280283
});
281284

282-
/** Whether the item is active. */
283-
readonly active = computed(() => this._pattern.active());
284-
285285
/** Whether this item is currently expanded, returning null if not expandable. */
286286
readonly expanded = computed(() =>
287287
this._pattern.expandable() ? this._pattern.expanded() : null,
288288
);
289289

290290
/** The level of the current item in a tree. */
291-
readonly level = computed(() => this._pattern.level());
291+
level: Signal<number>;
292292

293293
/** The position of this item among its siblings (1-based). */
294-
readonly posinset = computed(() => this._pattern.posinset());
294+
posinset: Signal<number>;
295295

296296
/** Whether the item is selected. */
297-
readonly selected = computed(() => this._pattern.selected());
297+
selected: Signal<boolean | undefined>;
298298

299299
/** Whether this item is visible. */
300-
readonly visible = computed(() => this._pattern.visible());
300+
visible: Signal<boolean>;
301301

302302
/** The UI pattern for this item. */
303303
_pattern: TreeItemPattern<V>;
@@ -336,6 +336,12 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
336336
children: computed(() => this._group()?.children() ?? []),
337337
hasChildren: computed(() => !!this._group()),
338338
});
339+
340+
this.active = this._pattern.active;
341+
this.level = this._pattern.level;
342+
this.posinset = this._pattern.posinset;
343+
this.selected = this._pattern.selected;
344+
this.visible = this._pattern.visible;
339345
}
340346

341347
ngOnDestroy() {

0 commit comments

Comments
 (0)