| 56 | }, |
| 57 | }) |
| 58 | export class TreeItem<V> extends DeferredContentAware implements OnInit, OnDestroy, HasElement { |
| 59 | /** A reference to the host element. */ |
| 60 | private readonly _elementRef = inject(ElementRef); |
| 61 | |
| 62 | /** A reference to the host element. */ |
| 63 | readonly element = this._elementRef.nativeElement as HTMLElement; |
| 64 | |
| 65 | /** The owned tree item group. */ |
| 66 | private readonly _group = signal<TreeItemGroup<V> | undefined>(undefined); |
| 67 | |
| 68 | /** A unique identifier for the tree item. */ |
| 69 | readonly id = input(inject(_IdGenerator).getId('ng-tree-item-', true)); |
| 70 | |
| 71 | /** The value of the tree item. */ |
| 72 | readonly value = input.required<V>(); |
| 73 | |
| 74 | /** The parent tree root or tree item group. */ |
| 75 | readonly parent = input.required<Tree<V> | TreeItemGroup<V>>(); |
| 76 | |
| 77 | /** Whether the tree item is disabled. */ |
| 78 | readonly disabled = input(false, {transform: booleanAttribute}); |
| 79 | |
| 80 | /** Whether the tree item is selectable. */ |
| 81 | readonly selectable = input<boolean>(true); |
| 82 | |
| 83 | /** Whether the tree item is expanded. */ |
| 84 | readonly expanded = model<boolean>(false); |
| 85 | |
| 86 | /** Optional label for typeahead. Defaults to the element's textContent. */ |
| 87 | readonly label = input<string>(); |
| 88 | |
| 89 | /** Search term for typeahead. */ |
| 90 | readonly searchTerm = computed(() => this.label() ?? this.element.textContent); |
| 91 | |
| 92 | /** The tree root. */ |
| 93 | readonly tree: Signal<Tree<V>> = computed(() => { |
| 94 | if (this.parent() instanceof Tree) { |
| 95 | return this.parent() as Tree<V>; |
| 96 | } |
| 97 | return (this.parent() as TreeItemGroup<V>).ownedBy().tree(); |
| 98 | }); |
| 99 | |
| 100 | /** Whether the item is active. */ |
| 101 | readonly active = computed(() => this._pattern.active()); |
| 102 | |
| 103 | /** The level of the current item in a tree. */ |
| 104 | readonly level = computed(() => this._pattern.level()); |
| 105 | |
| 106 | /** Whether the item is selected. */ |
| 107 | readonly selected = computed(() => this._pattern.selected()); |
| 108 | |
| 109 | /** Whether this item is visible due to all of its parents being expanded. */ |
| 110 | readonly visible = computed(() => this._pattern.visible()); |
| 111 | |
| 112 | /** Whether the tree is expanded. Use this value for aria-expanded. */ |
| 113 | protected readonly _expanded: Signal<boolean | undefined> = computed(() => |
| 114 | this._pattern.expandable() ? this._pattern.expanded() : undefined, |
| 115 | ); |
nothing calls this directly
no test coverage detected
searching dependent graphs…