MCPcopy Create free account
hub / github.com/angular/components / TreeItemPattern

Class TreeItemPattern

src/aria/private/tree/tree.ts:37–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35 * Represents an item in a Tree.
36 */
37export class TreeItemPattern<V> implements TreeItem<V, TreeItemPattern<V>> {
38 /** A unique identifier for this item. */
39 readonly id: SignalLike<string> = () => this.inputs.id();
40
41 /** The value of this item. */
42 readonly value: SignalLike<V> = () => this.inputs.value();
43
44 /** A reference to the item element. */
45 readonly element: SignalLike<HTMLElement> = () => this.inputs.element()!;
46
47 /** Whether the item is disabled. */
48 readonly disabled: SignalLike<boolean> = () => this.inputs.disabled();
49
50 /** The text used by the typeahead search. */
51 readonly searchTerm: SignalLike<string> = () => this.inputs.searchTerm();
52
53 /** The tree pattern this item belongs to. */
54 readonly tree: SignalLike<TreePattern<V>> = () => this.inputs.tree();
55
56 /** The parent item. */
57 readonly parent: SignalLike<TreeItemPattern<V> | undefined> = computed(() => {
58 const parent = this.inputs.parent();
59 return parent instanceof TreeItemPattern ? parent : undefined;
60 });
61
62 /** The children items. */
63 readonly children: SignalLike<TreeItemPattern<V>[]> = () => this.inputs.children() ?? [];
64
65 /** The position of this item among its siblings. */
66 readonly index = computed(() => this.tree().inputs.items().indexOf(this));
67
68 /** Whether the item is expandable. It's expandable if children item exist. */
69 readonly expandable: SignalLike<boolean> = () => this.inputs.hasChildren();
70
71 /** Whether the item is selectable. */
72 readonly selectable: SignalLike<boolean> = () => this.inputs.selectable();
73
74 /** Whether the item is expanded. */
75 readonly expanded: WritableSignalLike<boolean>;
76
77 /** The level of the current item in a tree. */
78 readonly level: SignalLike<number> = computed(() => this.inputs.parent().level() + 1);
79
80 /** Whether this item is visible. */
81 readonly visible: SignalLike<boolean> = computed(
82 () => this.inputs.parent().expanded() && this.inputs.parent().visible(),
83 );
84
85 /** The number of items under the same parent at the same level. */
86 readonly setsize = computed(() => this.inputs.parent().children().length);
87
88 /** The position of this item among its siblings (1-based). */
89 readonly posinset = computed(() => this.inputs.parent().children().indexOf(this) + 1);
90
91 /** Whether the item is active. */
92 readonly active = computed(() => this.tree().activeItem() === this);
93
94 /** The tab index of the item. */

Callers

nothing calls this directly

Calls 12

computedFunction · 0.90
parentMethod · 0.80
expandedMethod · 0.80
visibleMethod · 0.80
activeItemMethod · 0.80
idMethod · 0.45
valueMethod · 0.45
elementMethod · 0.45
disabledMethod · 0.45
selectableMethod · 0.45
levelMethod · 0.45
getItemTabindexMethod · 0.45

Tested by

no test coverage detected