Skip to content

Commit 40ab03e

Browse files
committed
refactor(aria/tree): Add accessors for pattern properties
1 parent 7eaf897 commit 40ab03e

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
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 tabindex of the tree. */

src/aria/tree/tree.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ function sortDirectives(a: HasElement, b: HasElement) {
7272
'[attr.aria-orientation]': '_pattern.orientation()',
7373
'[attr.aria-multiselectable]': '_pattern.multi()',
7474
'[attr.aria-disabled]': '_pattern.disabled()',
75-
'[attr.aria-activedescendant]': '_pattern.activedescendant()',
75+
'[attr.aria-activedescendant]': 'activedescendant()',
7676
'[tabindex]': '_pattern.tabindex()',
7777
'(keydown)': '_pattern.onKeydown($event)',
7878
'(pointerdown)': '_pattern.onPointerdown($event)',
@@ -132,6 +132,18 @@ export class Tree<V> {
132132
/** Whether the tree is in navigation mode. */
133133
readonly nav = input(false);
134134

135+
/** The id of the current active item. */
136+
readonly activedescendant = computed(() => this._pattern.activedescendant());
137+
138+
/** The direct children of the root (top-level tree items). */
139+
readonly children = computed(() => this._pattern.children());
140+
141+
/** Whether the tree selection follows focus. */
142+
readonly followFocus = computed(() => this._pattern.followFocus());
143+
144+
/** All currently visible tree items. An item is visible if their parent is expanded. */
145+
readonly visibleItems = computed(() => this._pattern.visible());
146+
135147
/** The aria-current type. */
136148
readonly currentType = input<'page' | 'step' | 'location' | 'date' | 'time' | 'true' | 'false'>(
137149
'page',
@@ -215,16 +227,16 @@ export class Tree<V> {
215227
exportAs: 'ngTreeItem',
216228
host: {
217229
'class': 'ng-treeitem',
218-
'[attr.data-active]': '_pattern.active()',
230+
'[attr.data-active]': 'active()',
219231
'role': 'treeitem',
220232
'[id]': '_pattern.id()',
221-
'[attr.aria-expanded]': '_pattern.expandable() ? _pattern.expanded() : null',
222-
'[attr.aria-selected]': '_pattern.selected()',
233+
'[attr.aria-expanded]': 'expanded()',
234+
'[attr.aria-selected]': 'selected()',
223235
'[attr.aria-current]': '_pattern.current()',
224236
'[attr.aria-disabled]': '_pattern.disabled()',
225-
'[attr.aria-level]': '_pattern.level()',
237+
'[attr.aria-level]': 'level()',
226238
'[attr.aria-setsize]': '_pattern.setsize()',
227-
'[attr.aria-posinset]': '_pattern.posinset()',
239+
'[attr.aria-posinset]': 'posinset()',
228240
'[attr.tabindex]': '_pattern.tabindex()',
229241
},
230242
})
@@ -267,6 +279,26 @@ export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestr
267279
return (this.parent() as TreeItemGroup<V>).ownedBy().tree();
268280
});
269281

282+
/** Whether the item is active. */
283+
readonly active = computed(() => this._pattern.active());
284+
285+
/** Whether this item is currently expanded, returning null if not expandable. */
286+
readonly expanded = computed(() =>
287+
this._pattern.expandable() ? this._pattern.expanded() : null,
288+
);
289+
290+
/** The level of the current item in a tree. */
291+
readonly level = computed(() => this._pattern.level());
292+
293+
/** The position of this item among its siblings (1-based). */
294+
readonly posinset = computed(() => this._pattern.posinset());
295+
296+
/** Whether the item is selected. */
297+
readonly selected = computed(() => this._pattern.selected());
298+
299+
/** Whether this item is visible. */
300+
readonly visible = computed(() => this._pattern.visible());
301+
270302
/** The UI pattern for this item. */
271303
_pattern: TreeItemPattern<V>;
272304

0 commit comments

Comments
 (0)