Skip to content

Commit 450a94d

Browse files
committed
refactor(aria/tree): Add accessors for pattern properties
1 parent 521493e commit 450a94d

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/aria/private/tree/tree.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ export class TreePattern<V> {
185185
/** The root is always expanded. */
186186
readonly expanded = () => true;
187187

188-
/** The roow is always visible. */
188+
/** The root is always visible. */
189189
readonly visible = () => true;
190190

191191
/** The tab index of the tree. */

src/aria/tree/tree.ts

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,14 +220,14 @@ export class Tree<V> {
220220
exportAs: 'ngTreeItem',
221221
host: {
222222
'class': 'ng-treeitem',
223-
'[attr.data-active]': '_pattern.active()',
223+
'[attr.data-active]': 'active()',
224224
'role': 'treeitem',
225225
'[id]': '_pattern.id()',
226-
'[attr.aria-expanded]': '_pattern.expandable() ? _pattern.expanded() : null',
227-
'[attr.aria-selected]': '_pattern.selected()',
226+
'[attr.aria-expanded]': 'expanded()',
227+
'[attr.aria-selected]': 'selected()',
228228
'[attr.aria-current]': '_pattern.current()',
229229
'[attr.aria-disabled]': '_pattern.disabled()',
230-
'[attr.aria-level]': '_pattern.level()',
230+
'[attr.aria-level]': 'level()',
231231
'[attr.aria-setsize]': '_pattern.setsize()',
232232
'[attr.aria-posinset]': '_pattern.posinset()',
233233
'[attr.tabindex]': '_pattern.tabIndex()',
@@ -272,6 +272,23 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
272272
return (this.parent() as TreeItemGroup<V>).ownedBy().tree();
273273
});
274274

275+
/** Whether the item is active. */
276+
readonly active = computed(() => this._pattern.active());
277+
278+
/** Whether this item is currently expanded, returning null if not expandable. */
279+
readonly expanded = computed(() =>
280+
this._pattern.expandable() ? this._pattern.expanded() : null,
281+
);
282+
283+
/** The level of the current item in a tree. */
284+
readonly level = computed(() => this._pattern.level());
285+
286+
/** Whether the item is selected. */
287+
readonly selected = computed(() => this._pattern.selected());
288+
289+
/** Whether this item is visible due to all of its parents being expanded. */
290+
readonly visible = computed(() => this._pattern.visible());
291+
275292
/** The UI pattern for this item. */
276293
_pattern: TreeItemPattern<V>;
277294

0 commit comments

Comments
 (0)