@@ -73,19 +73,6 @@ export class MatButtonToggleChange {
73
73
} )
74
74
export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
75
75
implements ControlValueAccessor , CanDisable {
76
-
77
- /** The value for the button toggle group. Should match currently selected button toggle. */
78
- private _value : any = null ;
79
-
80
- /** The HTML name attribute applied to toggles in this group. */
81
- private _name : string = `mat-button-toggle-group-${ _uniqueIdCounter ++ } ` ;
82
-
83
- /** Whether the button toggle group should be vertical. */
84
- private _vertical : boolean = false ;
85
-
86
- /** The currently selected button toggle, should match the value. */
87
- private _selected : MatButtonToggle | null = null ;
88
-
89
76
/**
90
77
* The method to be called in order to update ngModel.
91
78
* Now `ngModel` binding is not supported in multiple selection mode.
@@ -105,22 +92,25 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
105
92
this . _name = value ;
106
93
this . _updateButtonToggleNames ( ) ;
107
94
}
95
+ private _name : string = `mat-button-toggle-group-${ _uniqueIdCounter ++ } ` ;
108
96
109
97
/** Whether the toggle group is vertical. */
110
98
@Input ( )
111
99
get vertical ( ) : boolean { return this . _vertical ; }
112
100
set vertical ( value : boolean ) { this . _vertical = coerceBooleanProperty ( value ) ; }
101
+ private _vertical : boolean = false ;
113
102
114
103
/** Value of the toggle group. */
115
104
@Input ( )
116
105
get value ( ) : any { return this . _value ; }
117
- set value ( newValue : any ) {
118
- if ( this . _value != newValue ) {
119
- this . _value = newValue ;
120
- this . valueChange . emit ( newValue ) ;
106
+ set value ( value : any ) {
107
+ if ( this . _value != value ) {
108
+ this . _value = value ;
109
+ this . valueChange . emit ( value ) ;
121
110
this . _updateSelectedButtonToggleFromValue ( ) ;
122
111
}
123
112
}
113
+ private _value : any = null ;
124
114
125
115
/**
126
116
* Event that emits whenever the value of the group changes.
@@ -129,7 +119,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
129
119
*/
130
120
@Output ( ) readonly valueChange = new EventEmitter < any > ( ) ;
131
121
132
- /** Whether the toggle group is selected . */
122
+ /** The currently selected button toggle, should match the value . */
133
123
@Input ( )
134
124
get selected ( ) : MatButtonToggle | null { return this . _selected ; }
135
125
set selected ( selected : MatButtonToggle | null ) {
@@ -140,6 +130,7 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
140
130
selected . checked = true ;
141
131
}
142
132
}
133
+ private _selected : MatButtonToggle | null = null ;
143
134
144
135
/** Event emitted when the group's value changes. */
145
136
@Output ( ) readonly change : EventEmitter < MatButtonToggleChange > =
@@ -185,37 +176,23 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
185
176
this . change . emit ( event ) ;
186
177
}
187
178
188
- /**
189
- * Sets the model value. Implemented as part of ControlValueAccessor.
190
- * @param value Value to be set to the model.
191
- */
179
+ // Implemented as part of ControlValueAccessor.
192
180
writeValue ( value : any ) {
193
181
this . value = value ;
194
182
this . _changeDetector . markForCheck ( ) ;
195
183
}
196
184
197
- /**
198
- * Registers a callback that will be triggered when the value has changed.
199
- * Implemented as part of ControlValueAccessor.
200
- * @param fn On change callback function.
201
- */
185
+ // Implemented as part of ControlValueAccessor.
202
186
registerOnChange ( fn : ( value : any ) => void ) {
203
187
this . _controlValueAccessorChangeFn = fn ;
204
188
}
205
189
206
- /**
207
- * Registers a callback that will be triggered when the control has been touched.
208
- * Implemented as part of ControlValueAccessor.
209
- * @param fn On touch callback function.
210
- */
190
+ // Implemented as part of ControlValueAccessor.
211
191
registerOnTouched ( fn : any ) {
212
192
this . _onTouched = fn ;
213
193
}
214
194
215
- /**
216
- * Toggles the disabled state of the component. Implemented as part of ControlValueAccessor.
217
- * @param isDisabled Whether the component should be disabled.
218
- */
195
+ // Implemented as part of ControlValueAccessor.
219
196
setDisabledState ( isDisabled : boolean ) : void {
220
197
this . disabled = isDisabled ;
221
198
this . _markButtonTogglesForCheck ( ) ;
@@ -241,16 +218,11 @@ export class MatButtonToggleGroup extends _MatButtonToggleGroupMixinBase
241
218
} )
242
219
export class MatButtonToggleGroupMultiple extends _MatButtonToggleGroupMixinBase
243
220
implements CanDisable {
244
-
245
- /** Whether the button toggle group should be vertical. */
246
- private _vertical : boolean = false ;
247
-
248
221
/** Whether the toggle group is vertical. */
249
222
@Input ( )
250
223
get vertical ( ) : boolean { return this . _vertical ; }
251
- set vertical ( value ) {
252
- this . _vertical = coerceBooleanProperty ( value ) ;
253
- }
224
+ set vertical ( value : boolean ) { this . _vertical = coerceBooleanProperty ( value ) ; }
225
+ private _vertical : boolean = false ;
254
226
}
255
227
256
228
/** Single button inside of a toggle group. */
@@ -283,18 +255,9 @@ export class MatButtonToggle implements OnInit, OnDestroy {
283
255
*/
284
256
@Input ( 'aria-labelledby' ) ariaLabelledby : string | null = null ;
285
257
286
- /** Whether or not this button toggle is checked. */
287
- private _checked : boolean = false ;
288
-
289
258
/** Type of the button toggle. Either 'radio' or 'checkbox'. */
290
259
_type : ToggleType ;
291
260
292
- /** Whether or not this button toggle is disabled. */
293
- private _disabled : boolean = false ;
294
-
295
- /** Value assigned to this button toggle. */
296
- private _value : any = null ;
297
-
298
261
/** Whether or not the button toggle is a single selection. */
299
262
private _isSingleSelector : boolean = false ;
300
263
@@ -321,19 +284,20 @@ export class MatButtonToggle implements OnInit, OnDestroy {
321
284
/** Whether the button is checked. */
322
285
@Input ( )
323
286
get checked ( ) : boolean { return this . _checked ; }
324
- set checked ( newCheckedState : boolean ) {
325
- if ( this . _isSingleSelector && newCheckedState ) {
287
+ set checked ( value : boolean ) {
288
+ if ( this . _isSingleSelector && value ) {
326
289
// Notify all button toggles with the same name (in the same group) to un-check.
327
290
this . _buttonToggleDispatcher . notify ( this . id , this . name ) ;
328
291
this . _changeDetectorRef . markForCheck ( ) ;
329
292
}
330
293
331
- this . _checked = newCheckedState ;
294
+ this . _checked = value ;
332
295
333
- if ( newCheckedState && this . _isSingleSelector && this . buttonToggleGroup . value != this . value ) {
296
+ if ( value && this . _isSingleSelector && this . buttonToggleGroup . value != this . value ) {
334
297
this . buttonToggleGroup . selected = this ;
335
298
}
336
299
}
300
+ private _checked : boolean = false ;
337
301
338
302
/** MatButtonToggleGroup reads this to assign its own value. */
339
303
@Input ( )
@@ -346,16 +310,16 @@ export class MatButtonToggle implements OnInit, OnDestroy {
346
310
this . _value = value ;
347
311
}
348
312
}
313
+ private _value : any = null ;
349
314
350
315
/** Whether the button is disabled. */
351
316
@Input ( )
352
317
get disabled ( ) : boolean {
353
318
return this . _disabled || ( this . buttonToggleGroup != null && this . buttonToggleGroup . disabled ) ||
354
319
( this . buttonToggleGroupMultiple != null && this . buttonToggleGroupMultiple . disabled ) ;
355
320
}
356
- set disabled ( value : boolean ) {
357
- this . _disabled = coerceBooleanProperty ( value ) ;
358
- }
321
+ set disabled ( value : boolean ) { this . _disabled = coerceBooleanProperty ( value ) ; }
322
+ private _disabled : boolean = false ;
359
323
360
324
/** Event emitted when the group value changes. */
361
325
@Output ( ) readonly change : EventEmitter < MatButtonToggleChange > =
@@ -403,7 +367,7 @@ export class MatButtonToggle implements OnInit, OnDestroy {
403
367
}
404
368
405
369
/** Focuses the button. */
406
- focus ( ) {
370
+ focus ( ) : void {
407
371
this . _inputElement . nativeElement . focus ( ) ;
408
372
}
409
373
@@ -454,7 +418,7 @@ export class MatButtonToggle implements OnInit, OnDestroy {
454
418
}
455
419
456
420
// Unregister buttonToggleDispatcherListener on destroy
457
- ngOnDestroy ( ) : void {
421
+ ngOnDestroy ( ) {
458
422
this . _removeUniqueSelectionListener ( ) ;
459
423
}
460
424
0 commit comments