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