| 78 | imports: [MatPseudoCheckbox, MatRipple], |
| 79 | }) |
| 80 | export class MatOption<T = any> implements FocusableOption, AfterViewChecked, OnDestroy { |
| 81 | private _element = inject<ElementRef<HTMLElement>>(ElementRef); |
| 82 | _changeDetectorRef = inject(ChangeDetectorRef); |
| 83 | private _parent = inject<MatOptionParentComponent>(MAT_OPTION_PARENT_COMPONENT, {optional: true}); |
| 84 | group = inject<MatOptgroup>(MAT_OPTGROUP, {optional: true}); |
| 85 | |
| 86 | private _signalDisableRipple = false; |
| 87 | private _selected = false; |
| 88 | private _active = false; |
| 89 | private _mostRecentViewValue = ''; |
| 90 | |
| 91 | /** Whether the wrapping component is in multiple selection mode. */ |
| 92 | get multiple() { |
| 93 | return this._parent && this._parent.multiple; |
| 94 | } |
| 95 | |
| 96 | /** Whether or not the option is currently selected. */ |
| 97 | get selected(): boolean { |
| 98 | return this._selected; |
| 99 | } |
| 100 | |
| 101 | /** The form value of the option. */ |
| 102 | @Input() value!: T; |
| 103 | |
| 104 | /** The unique ID of the option. */ |
| 105 | @Input() id: string = inject(_IdGenerator).getId('mat-option-'); |
| 106 | |
| 107 | /** Whether the option is disabled. */ |
| 108 | @Input({transform: booleanAttribute}) |
| 109 | get disabled(): boolean { |
| 110 | return (this.group && this.group.disabled) || this._disabled(); |
| 111 | } |
| 112 | set disabled(value: boolean) { |
| 113 | this._disabled.set(value); |
| 114 | } |
| 115 | private _disabled = signal(false); |
| 116 | |
| 117 | /** Whether ripples for the option are disabled. */ |
| 118 | get disableRipple(): boolean { |
| 119 | return this._signalDisableRipple |
| 120 | ? (this._parent!.disableRipple as Signal<boolean>)() |
| 121 | : !!this._parent?.disableRipple; |
| 122 | } |
| 123 | |
| 124 | /** Whether to display checkmark for single-selection. */ |
| 125 | get hideSingleSelectionIndicator(): boolean { |
| 126 | return !!(this._parent && this._parent.hideSingleSelectionIndicator); |
| 127 | } |
| 128 | |
| 129 | /** Event emitted when the option is selected or deselected. */ |
| 130 | // tslint:disable-next-line:no-output-on-prefix |
| 131 | @Output() readonly onSelectionChange = new EventEmitter<MatOptionSelectionChange<T>>(); |
| 132 | |
| 133 | /** Element containing the option's text. */ |
| 134 | @ViewChild('text', {static: true}) _text: ElementRef<HTMLElement> | undefined; |
| 135 | |
| 136 | /** Emits when the state of the option changes and any parents have to be notified. */ |
| 137 | readonly _stateChanges = new Subject<void>(); |