| 51 | }, |
| 52 | }) |
| 53 | export class Option<V> implements OnInit, OnDestroy { |
| 54 | /** A reference to the host element. */ |
| 55 | readonly element = inject(ElementRef).nativeElement as HTMLElement; |
| 56 | |
| 57 | /** Whether the option is currently active (focused). */ |
| 58 | readonly active = computed(() => this._pattern.active()); |
| 59 | |
| 60 | /** The parent Listbox. */ |
| 61 | private readonly _listbox = inject(LISTBOX); |
| 62 | |
| 63 | /** A unique identifier for the option. */ |
| 64 | readonly id = input(inject(_IdGenerator).getId('ng-option-', true)); |
| 65 | |
| 66 | /** The parent Listbox UIPattern. */ |
| 67 | private readonly _listboxPattern = computed(() => this._listbox._pattern); |
| 68 | |
| 69 | /** The value of the option. */ |
| 70 | readonly value = input.required<V>(); |
| 71 | |
| 72 | /** Whether an item is disabled. */ |
| 73 | readonly disabled = input(false, {transform: booleanAttribute}); |
| 74 | |
| 75 | /** The text used by the typeahead search. */ |
| 76 | readonly label = input<string>(); |
| 77 | |
| 78 | /** Whether the option is selected. */ |
| 79 | readonly selected = computed(() => this._pattern.selected()); |
| 80 | |
| 81 | /** The Option UIPattern. */ |
| 82 | readonly _pattern = new OptionPattern<V>({ |
| 83 | ...this, |
| 84 | id: this.id, |
| 85 | value: this.value, |
| 86 | listbox: this._listboxPattern, |
| 87 | element: () => this.element, |
| 88 | searchTerm: () => this.label() ?? '', |
| 89 | }); |
| 90 | |
| 91 | ngOnInit() { |
| 92 | this._listbox._collection.register(this); |
| 93 | } |
| 94 | |
| 95 | ngOnDestroy() { |
| 96 | this._listbox._collection.unregister(this); |
| 97 | } |
| 98 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…