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

Class CdkOption

src/cdk/listbox/listbox.ts:102–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100 },
101})
102export class CdkOption<T = unknown> implements ListKeyManagerOption, Highlightable, OnDestroy {
103 /** The id of the option's host element. */
104 @Input()
105 get id() {
106 return this._id || this._generatedId;
107 }
108 set id(value) {
109 this._id = value;
110 }
111 private _id: string | undefined;
112 private _generatedId = inject(_IdGenerator).getId('cdk-option-');
113
114 /** The value of this option. */
115 @Input('cdkOption') value!: T;
116
117 /**
118 * The text used to locate this item during listbox typeahead. If not specified,
119 * the `textContent` of the item will be used.
120 */
121 @Input('cdkOptionTypeaheadLabel') typeaheadLabel: string | null = null;
122
123 /** Whether this option is disabled. */
124 @Input({alias: 'cdkOptionDisabled', transform: booleanAttribute})
125 get disabled(): boolean {
126 return this.listbox.disabled || this._disabled();
127 }
128 set disabled(value: boolean) {
129 this._disabled.set(value);
130 }
131 private _disabled = signal(false);
132
133 /** The tabindex of the option when it is enabled. */
134 @Input({
135 alias: 'tabindex',
136 transform: (value: unknown) => (value == null ? undefined : numberAttribute(value)),
137 })
138 get enabledTabIndex() {
139 return this._enabledTabIndex() === undefined
140 ? this.listbox.enabledTabIndex
141 : this._enabledTabIndex();
142 }
143 set enabledTabIndex(value) {
144 this._enabledTabIndex.set(value);
145 }
146 private _enabledTabIndex = signal<number | null | undefined>(undefined);
147
148 /** The option's host element */
149 readonly element: HTMLElement = inject(ElementRef).nativeElement;
150
151 /** The parent listbox this option belongs to. */
152 protected readonly listbox: CdkListbox<T> = inject(CdkListbox);
153
154 /** Emits when the option is destroyed. */
155 protected destroyed = new Subject<void>();
156
157 /** Emits when the option is clicked. */
158 readonly _clicked = new Subject<MouseEvent>();
159

Callers

nothing calls this directly

Calls 2

signalFunction · 0.85
getIdMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…