MCPcopy
hub / github.com/angular/components / TreeItemPattern

Class TreeItemPattern

src/aria/private/tree/tree.ts:36–121  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…