@@ -28,6 +28,8 @@ import {
2828 QueryList ,
2929 ViewChild ,
3030 ViewEncapsulation ,
31+ InjectionToken ,
32+ Inject ,
3133} from '@angular/core' ;
3234import { ControlValueAccessor , NG_VALUE_ACCESSOR } from '@angular/forms' ;
3335import {
@@ -40,6 +42,26 @@ import {
4042/** Acceptable types for a button toggle. */
4143export type ToggleType = 'checkbox' | 'radio' ;
4244
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+
4365/**
4466 * Provider Expression that allows mat-button-toggle-group to register as a ControlValueAccessor.
4567 * This allows it to support [(ngModel)].
@@ -80,12 +102,12 @@ export class MatButtonToggleChange {
80102 'role' : 'group' ,
81103 'class' : 'mat-button-toggle-group' ,
82104 '[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"' ,
84107 } ,
85108 exportAs : 'matButtonToggleGroup' ,
86109} )
87110export class MatButtonToggleGroup implements ControlValueAccessor , OnInit , AfterContentInit {
88-
89111 private _vertical = false ;
90112 private _multiple = false ;
91113 private _disabled = false ;
@@ -111,6 +133,9 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
111133 /** Child button toggle buttons. */
112134 @ContentChildren ( forwardRef ( ( ) => MatButtonToggle ) ) _buttonToggles : QueryList < MatButtonToggle > ;
113135
136+ /** The appearance for all the buttons in the group. */
137+ @Input ( ) appearance : MatButtonToggleAppearance ;
138+
114139 /** `name` attribute for the underlying `input` element. */
115140 @Input ( )
116141 get name ( ) : string { return this . _name ; }
@@ -181,7 +206,14 @@ export class MatButtonToggleGroup implements ControlValueAccessor, OnInit, After
181206 @Output ( ) readonly change : EventEmitter < MatButtonToggleChange > =
182207 new EventEmitter < MatButtonToggleChange > ( ) ;
183208
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+ }
185217
186218 ngOnInit ( ) {
187219 this . _selectionModel = new SelectionModel < MatButtonToggle > ( this . multiple , undefined , false ) ;
@@ -331,6 +363,7 @@ export const _MatButtonToggleMixinBase: CanDisableRippleCtor & typeof MatButtonT
331363 '[class.mat-button-toggle-standalone]' : '!buttonToggleGroup' ,
332364 '[class.mat-button-toggle-checked]' : 'checked' ,
333365 '[class.mat-button-toggle-disabled]' : 'disabled' ,
366+ '[class.mat-button-toggle-appearance-standard]' : 'appearance === "standard"' ,
334367 'class' : 'mat-button-toggle' ,
335368 // Clear out the native tabindex here since we forward it to the underlying button
336369 '[attr.tabindex]' : 'null' ,
@@ -377,6 +410,16 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
377410 /** Tabindex for the toggle. */
378411 @Input ( ) tabIndex : number | null ;
379412
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+
380423 /** Whether the button is checked. */
381424 @Input ( )
382425 get checked ( ) : boolean {
@@ -413,12 +456,16 @@ export class MatButtonToggle extends _MatButtonToggleMixinBase implements OnInit
413456 private _elementRef : ElementRef < HTMLElement > ,
414457 private _focusMonitor : FocusMonitor ,
415458 // @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 ) {
417462 super ( ) ;
418463
419464 const parsedTabIndex = Number ( defaultTabIndex ) ;
420465 this . tabIndex = ( parsedTabIndex || parsedTabIndex === 0 ) ? parsedTabIndex : null ;
421466 this . buttonToggleGroup = toggleGroup ;
467+ this . appearance =
468+ defaultOptions && defaultOptions . appearance ? defaultOptions . appearance : 'standard' ;
422469 }
423470
424471 ngOnInit ( ) {
0 commit comments