| 138 | exportAs: 'matButtonToggleGroup', |
| 139 | }) |
| 140 | export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, AfterContentInit { |
| 141 | private _changeDetector = inject(ChangeDetectorRef); |
| 142 | private _dir = inject(Directionality, {optional: true}); |
| 143 | |
| 144 | private _multiple = false; |
| 145 | private _disabled = false; |
| 146 | private _disabledInteractive = false; |
| 147 | private _selectionModel!: SelectionModel<MatButtonToggle>; |
| 148 | |
| 149 | /** |
| 150 | * Reference to the raw value that the consumer tried to assign. The real |
| 151 | * value will exclude any values from this one that don't correspond to a |
| 152 | * toggle. Useful for the cases where the value is assigned before the toggles |
| 153 | * have been initialized or at the same that they're being swapped out. |
| 154 | */ |
| 155 | private _rawValue: any; |
| 156 | |
| 157 | /** |
| 158 | * The method to be called in order to update ngModel. |
| 159 | * Now `ngModel` binding is not supported in multiple selection mode. |
| 160 | */ |
| 161 | _controlValueAccessorChangeFn: (value: any) => void = () => {}; |
| 162 | |
| 163 | /** onTouch function registered via registerOnTouch (ControlValueAccessor). */ |
| 164 | _onTouched: () => any = () => {}; |
| 165 | |
| 166 | /** Child button toggle buttons. */ |
| 167 | @ContentChildren(forwardRef(() => MatButtonToggle), { |
| 168 | // Note that this would technically pick up toggles |
| 169 | // from nested groups, but that's not a case that we support. |
| 170 | descendants: true, |
| 171 | }) |
| 172 | _buttonToggles!: QueryList<MatButtonToggle>; |
| 173 | |
| 174 | /** The appearance for all the buttons in the group. */ |
| 175 | @Input() appearance: MatButtonToggleAppearance; |
| 176 | |
| 177 | /** `name` attribute for the underlying `input` element. */ |
| 178 | @Input() |
| 179 | get name(): string { |
| 180 | return this._name; |
| 181 | } |
| 182 | set name(value: string) { |
| 183 | this._name = value; |
| 184 | this._markButtonsForCheck(); |
| 185 | } |
| 186 | private _name = inject(_IdGenerator).getId('mat-button-toggle-group-'); |
| 187 | |
| 188 | /** Whether the toggle group is vertical. */ |
| 189 | @Input({transform: booleanAttribute}) vertical: boolean = false; |
| 190 | |
| 191 | /** Value of the toggle group. */ |
| 192 | @Input() |
| 193 | get value(): any { |
| 194 | const selected = this._selectionModel ? this._selectionModel.selected : []; |
| 195 | |
| 196 | if (this.multiple) { |
| 197 | return selected.map(toggle => toggle.value); |
nothing calls this directly
no test coverage detected
searching dependent graphs…