@@ -28,6 +28,8 @@ import {
28
28
QueryList ,
29
29
ViewChild ,
30
30
ViewEncapsulation ,
31
+ InjectionToken ,
32
+ Inject ,
31
33
} from '@angular/core' ;
32
34
import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
33
35
import {
@@ -40,6 +42,26 @@ import {
40
42
/** Acceptable types for a button toggle. */
41
43
export type ToggleType = 'checkbox' | 'radio' ;
42
44
45
+ /** Possible appearance styles for the button toggle. */
46
+ export type MatButtonToggleAppearance = 'legacy' | 'standard' ;
47
+
48
+ /**
49
+ * Represents the default options for the button toggle that can be configured
50
+ * using the `MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS` injection token.
51
+ */
52
+ export interface MatButtonToggleDefaultOptions {
53
+ appearance ?: MatButtonToggleAppearance ;
54
+ }
55
+
56
+ /**
57
+ * Injection token that can be used to configure the
58
+ * default options for all button toggles within an app.
59
+ */
60
+ export const MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS =
61
+ new InjectionToken < MatButtonToggleDefaultOptions > ( 'MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS' ) ;
62
+
63
+
64
+
43
65
/**
44
66
* Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
45
67
* This allows it to support [(ngModel)].
@@ -80,12 +102,12 @@ export class MatButtonToggleChange {
80
102
'role' : 'group' ,
81
103
'class' : 'mat-button-toggle-group' ,
82
104
'[attr.aria-disabled]' : 'disabled' ,
83
- '[class.mat-button-toggle-vertical]' : 'vertical'
105
+ '[class.mat-button-toggle-vertical]' : 'vertical' ,
106
+ '[class.mat-button-toggle-group-appearance-standard]' : 'appearance === "standard"' ,
84
107
} ,
85
108
exportAs : 'matButtonToggleGroup' ,
86
109
} )
87
110
export class MatButtonToggleGroup implements ControlValueAccessor , OnInit , AfterContentInit {
88
-
89
111
private _vertical = false ;
90
112
private _multiple = false ;
91
113
private _disabled = false ;
@@ -111,6 +133,9 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
111
133
/** Child button toggle buttons. */
112
134
@ContentChildren ( forwardRef ( ( ) => MatButtonToggle ) ) _buttonToggles : QueryList < MatButtonToggle > ;
113
135
136
+ /** The appearance for all the buttons in the group. */
137
+ @Input ( ) appearance : MatButtonToggleAppearance ;
138
+
114
139
/** `name` attribute for the underlying `input` element. */
115
140
@Input ( )
116
141
get name ( ) : string { return this . _name ; }
@@ -181,7 +206,14 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
181
206
@Output ( ) readonly change : EventEmitter < MatButtonToggleChange > =
182
207
new EventEmitter < MatButtonToggleChange > ( ) ;
183
208
184
- constructor ( private _changeDetector : ChangeDetectorRef ) { }
209
+ constructor (
210
+ private _changeDetector : ChangeDetectorRef ,
211
+ @Optional ( ) @Inject ( MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS )
212
+ defaultOptions ?: MatButtonToggleDefaultOptions ) {
213
+
214
+ this . appearance =
215
+ defaultOptions && defaultOptions . appearance ? defaultOptions . appearance : 'standard' ;
216
+ }
185
217
186
218
ngOnInit ( ) {
187
219
this . _selectionModel = new SelectionModel < MatButtonToggle > ( this . multiple , undefined , false ) ;
@@ -331,6 +363,7 @@ export const _MatButtonToggleMixinBase: CanDisableRippleCtor & typeof MatButtonT
331
363
'[class.mat-button-toggle-standalone]' : '!buttonToggleGroup' ,
332
364
'[class.mat-button-toggle-checked]' : 'checked' ,
333
365
'[class.mat-button-toggle-disabled]' : 'disabled' ,
366
+ '[class.mat-button-toggle-appearance-standard]' : 'appearance === "standard"' ,
334
367
'class' : 'mat-button-toggle' ,
335
368
// Clear out the native tabindex here since we forward it to the underlying button
336
369
'[attr.tabindex]' : 'null' ,
@@ -377,6 +410,16 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
377
410
/** Tabindex for the toggle. */
378
411
@Input ( ) tabIndex : number | null ;
379
412
413
+ /** The appearance style of the button. */
414
+ @Input ( )
415
+ get appearance ( ) : MatButtonToggleAppearance {
416
+ return this . buttonToggleGroup ? this . buttonToggleGroup . appearance : this . _appearance ;
417
+ }
418
+ set appearance ( value : MatButtonToggleAppearance ) {
419
+ this . _appearance = value ;
420
+ }
421
+ private _appearance : MatButtonToggleAppearance ;
422
+
380
423
/** Whether the button is checked. */
381
424
@Input ( )
382
425
get checked ( ) : boolean {
@@ -413,12 +456,16 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
413
456
private _elementRef : ElementRef < HTMLElement > ,
414
457
private _focusMonitor : FocusMonitor ,
415
458
// @breaking -change 8.0.0 `defaultTabIndex` to be made a required parameter.
416
- @Attribute ( 'tabindex' ) defaultTabIndex : string ) {
459
+ @Attribute ( 'tabindex' ) defaultTabIndex : string ,
460
+ @Optional ( ) @Inject ( MAT_BUTTON_TOGGLE_DEFAULT_OPTIONS )
461
+ defaultOptions ?: MatButtonToggleDefaultOptions ) {
417
462
super ( ) ;
418
463
419
464
const parsedTabIndex = Number ( defaultTabIndex ) ;
420
465
this . tabIndex = ( parsedTabIndex || parsedTabIndex === 0 ) ? parsedTabIndex : null ;
421
466
this . buttonToggleGroup = toggleGroup ;
467
+ this . appearance =
468
+ defaultOptions && defaultOptions . appearance ? defaultOptions . appearance : 'standard' ;
422
469
}
423
470
424
471
ngOnInit ( ) {
0 commit comments