Skip to content

Commit 4c44304

Browse files
committed
refactor(aria/tree): Add accessors for pattern properties
1 parent 5cedd1a commit 4c44304

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
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: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ function sortDirectives(a: HasElement, b: HasElement) {
6969
'class': 'ng-tree',
7070
'role': 'tree',
7171
'[attr.id]': 'id()',
72-
'[attr.aria-orientation]': '_pattern.orientation()',
73-
'[attr.aria-multiselectable]': '_pattern.multi()',
72+
'[attr.aria-orientation]': 'orientation()',
73+
'[attr.aria-multiselectable]': '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()',
223-
'[attr.aria-current]': '_pattern.current()',
233+
'[attr.aria-expanded]': 'expanded()',
234+
'[attr.aria-selected]': 'selected()',
235+
'[attr.aria-current]': '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,29 @@ 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+
/** The current type of this item. */
286+
readonly current = computed(() => this._pattern.current());
287+
288+
/** Whether this item is currently expanded, returning null if not expandable. */
289+
readonly expanded = computed(() =>
290+
this._pattern.expandable() ? this._pattern.expanded() : null,
291+
);
292+
293+
/** The level of the current item in a tree. */
294+
readonly level = computed(() => this._pattern.level());
295+
296+
/** The position of this item among its siblings (1-based). */
297+
readonly posinset = computed(() => this._pattern.posinset());
298+
299+
/** Whether the item is selected. */
300+
readonly selected = computed(() => this._pattern.selected());
301+
302+
/** Whether this item is visible. */
303+
readonly visible = computed(() => this._pattern.visible());
304+
270305
/** The UI pattern for this item. */
271306
_pattern: TreeItemPattern<V>;
272307

0 commit comments

Comments
 (0)