@@ -155,13 +155,7 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
155
155
}
156
156
set name ( value : string ) {
157
157
this . _name = value ;
158
-
159
- if ( this . _buttonToggles ) {
160
- this . _buttonToggles . forEach ( toggle => {
161
- toggle . name = this . _name ;
162
- toggle . _markForCheck ( ) ;
163
- } ) ;
164
- }
158
+ this . _markButtonsForCheck ( ) ;
165
159
}
166
160
private _name = `mat-button-toggle-group-${ uniqueIdCounter ++ } ` ;
167
161
@@ -210,6 +204,7 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
210
204
}
211
205
set multiple ( value : BooleanInput ) {
212
206
this . _multiple = coerceBooleanProperty ( value ) ;
207
+ this . _markButtonsForCheck ( ) ;
213
208
}
214
209
215
210
/** Whether multiple button toggle group is disabled. */
@@ -219,10 +214,7 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
219
214
}
220
215
set disabled ( value : BooleanInput ) {
221
216
this . _disabled = coerceBooleanProperty ( value ) ;
222
-
223
- if ( this . _buttonToggles ) {
224
- this . _buttonToggles . forEach ( toggle => toggle . _markForCheck ( ) ) ;
225
- }
217
+ this . _markButtonsForCheck ( ) ;
226
218
}
227
219
228
220
/** Event emitted when the group's value changes. */
@@ -387,6 +379,11 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
387
379
// it is used by Angular to sync up the two-way data binding.
388
380
this . valueChange . emit ( this . value ) ;
389
381
}
382
+
383
+ /** Marks all of the child button toggles to be checked. */
384
+ private _markButtonsForCheck ( ) {
385
+ this . _buttonToggles ?. forEach ( toggle => toggle . _markForCheck ( ) ) ;
386
+ }
390
387
}
391
388
392
389
// Boilerplate for applying mixins to the MatButtonToggle class.
@@ -420,7 +417,6 @@ export class MatButtonToggle
420
417
extends _MatButtonToggleBase
421
418
implements OnInit , AfterViewInit , CanDisableRipple , OnDestroy
422
419
{
423
- private _isSingleSelector = false ;
424
420
private _checked = false ;
425
421
426
422
/**
@@ -521,13 +517,8 @@ export class MatButtonToggle
521
517
522
518
ngOnInit ( ) {
523
519
const group = this . buttonToggleGroup ;
524
- this . _isSingleSelector = group && ! group . multiple ;
525
520
this . id = this . id || `mat-button-toggle-${ uniqueIdCounter ++ } ` ;
526
521
527
- if ( this . _isSingleSelector ) {
528
- this . name = group . name ;
529
- }
530
-
531
522
if ( group ) {
532
523
if ( group . _isPrechecked ( this ) ) {
533
524
this . checked = true ;
@@ -564,7 +555,7 @@ export class MatButtonToggle
564
555
565
556
/** Checks the button toggle due to an interaction with the underlying native button. */
566
557
_onButtonClick ( ) {
567
- const newChecked = this . _isSingleSelector ? true : ! this . _checked ;
558
+ const newChecked = this . _isSingleSelector ( ) ? true : ! this . _checked ;
568
559
569
560
if ( newChecked !== this . _checked ) {
570
561
this . _checked = newChecked ;
@@ -587,4 +578,17 @@ export class MatButtonToggle
587
578
// Use `markForCheck` to explicit update button toggle's status.
588
579
this . _changeDetectorRef . markForCheck ( ) ;
589
580
}
581
+
582
+ /** Gets the name that should be assigned to the inner DOM node. */
583
+ _getButtonName ( ) : string | null {
584
+ if ( this . _isSingleSelector ( ) ) {
585
+ return this . buttonToggleGroup . name ;
586
+ }
587
+ return this . name || null ;
588
+ }
589
+
590
+ /** Whether the toggle is in single selection mode. */
591
+ private _isSingleSelector ( ) : boolean {
592
+ return this . buttonToggleGroup && ! this . buttonToggleGroup . multiple ;
593
+ }
590
594
}
0 commit comments