| 261 | ], |
| 262 | }) |
| 263 | export class CdkListbox<T = unknown> implements AfterContentInit, OnDestroy, ControlValueAccessor { |
| 264 | private _cleanupWindowBlur: (() => void) | undefined; |
| 265 | |
| 266 | /** The id of the option's host element. */ |
| 267 | @Input() |
| 268 | get id() { |
| 269 | return this._id || this._generatedId; |
| 270 | } |
| 271 | set id(value) { |
| 272 | this._id = value; |
| 273 | } |
| 274 | private _id: string | undefined; |
| 275 | private _generatedId = inject(_IdGenerator).getId('cdk-listbox-'); |
| 276 | |
| 277 | /** The tabindex to use when the listbox is enabled. */ |
| 278 | @Input('tabindex') |
| 279 | get enabledTabIndex() { |
| 280 | return this._enabledTabIndex() === undefined ? 0 : this._enabledTabIndex(); |
| 281 | } |
| 282 | set enabledTabIndex(value) { |
| 283 | this._enabledTabIndex.set(value); |
| 284 | } |
| 285 | private _enabledTabIndex = signal<number | null | undefined>(undefined); |
| 286 | |
| 287 | /** The value selected in the listbox, represented as an array of option values. */ |
| 288 | @Input('cdkListboxValue') |
| 289 | get value(): readonly T[] { |
| 290 | return this._invalid ? [] : this.selectionModel.selected; |
| 291 | } |
| 292 | set value(value: readonly T[]) { |
| 293 | this._setSelection(value); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Whether the listbox allows multiple options to be selected. If the value switches from `true` |
| 298 | * to `false`, and more than one option is selected, all options are deselected. |
| 299 | */ |
| 300 | @Input({alias: 'cdkListboxMultiple', transform: booleanAttribute}) |
| 301 | get multiple(): boolean { |
| 302 | return this.selectionModel.multiple; |
| 303 | } |
| 304 | set multiple(value: boolean) { |
| 305 | this.selectionModel.multiple = value; |
| 306 | |
| 307 | if (this.options) { |
| 308 | this._updateInternalValue(); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | /** Whether the listbox is disabled. */ |
| 313 | @Input({alias: 'cdkListboxDisabled', transform: booleanAttribute}) |
| 314 | get disabled() { |
| 315 | return this._disabled(); |
| 316 | } |
| 317 | set disabled(value: boolean) { |
| 318 | this._disabled.set(value); |
| 319 | } |
| 320 | private _disabled = signal(false); |