77 */
88
99import { FocusMonitor , FocusOrigin } from '@angular/cdk/a11y' ;
10- import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
1110import { Platform } from '@angular/cdk/platform' ;
1211import {
1312 AfterViewInit ,
13+ booleanAttribute ,
1414 Directive ,
1515 ElementRef ,
1616 inject ,
17+ Input ,
1718 NgZone ,
19+ numberAttribute ,
1820 OnDestroy ,
1921 OnInit ,
2022} from '@angular/core' ;
21- import {
22- CanColor ,
23- CanDisable ,
24- CanDisableRipple ,
25- MatRipple ,
26- mixinColor ,
27- mixinDisabled ,
28- mixinDisableRipple ,
29- MatRippleLoader ,
30- } from '@angular/material/core' ;
31-
32- /** Inputs common to all buttons. */
33- export const MAT_BUTTON_INPUTS = [ 'disabled' , 'disableRipple' , 'color' ] ;
23+ import { MatRipple , MatRippleLoader } from '@angular/material/core' ;
3424
3525/** Shared host configuration for all buttons */
3626export const MAT_BUTTON_HOST = {
@@ -43,6 +33,7 @@ export const MAT_BUTTON_HOST = {
4333 // Add a class that applies to all buttons. This makes it easier to target if somebody
4434 // wants to target all Material buttons.
4535 '[class.mat-mdc-button-base]' : 'true' ,
36+ '[class]' : 'color ? "mat-" + color : ""' ,
4637} ;
4738
4839/** List of classes to add to buttons instances based on host attribute selector. */
@@ -77,24 +68,9 @@ const HOST_SELECTOR_MDC_CLASS_PAIR: {selector: string; mdcClasses: string[]}[] =
7768 } ,
7869] ;
7970
80- // Boilerplate for applying mixins to MatButton.
81- /** @docs -private */
82- export const _MatButtonMixin = mixinColor (
83- mixinDisabled (
84- mixinDisableRipple (
85- class {
86- constructor ( public _elementRef : ElementRef ) { }
87- } ,
88- ) ,
89- ) ,
90- ) ;
91-
9271/** Base class for all buttons. */
9372@Directive ( )
94- export class MatButtonBase
95- extends _MatButtonMixin
96- implements CanDisable , CanColor , CanDisableRipple , AfterViewInit , OnDestroy
97- {
73+ export class MatButtonBase implements AfterViewInit , OnDestroy {
9874 private readonly _focusMonitor = inject ( FocusMonitor ) ;
9975
10076 /**
@@ -118,41 +94,41 @@ export class MatButtonBase
11894 this . _rippleLoader ?. attachRipple ( this . _elementRef . nativeElement , v ) ;
11995 }
12096
121- // We override `disableRipple` and `disabled` so we can hook into
122- // their setters and update the ripple disabled state accordingly.
97+ /** Theme color palette of the button */
98+ @ Input ( ) color ?: string | null ;
12399
124100 /** Whether the ripple effect is disabled or not. */
125- override get disableRipple ( ) : boolean {
101+ @Input ( { transform : booleanAttribute } )
102+ get disableRipple ( ) : boolean {
126103 return this . _disableRipple ;
127104 }
128- override set disableRipple ( value : any ) {
129- this . _disableRipple = coerceBooleanProperty ( value ) ;
105+ set disableRipple ( value : any ) {
106+ this . _disableRipple = value ;
130107 this . _updateRippleDisabled ( ) ;
131108 }
132109 private _disableRipple : boolean = false ;
133110
134- override get disabled ( ) : boolean {
111+ @Input ( { transform : booleanAttribute } )
112+ get disabled ( ) : boolean {
135113 return this . _disabled ;
136114 }
137- override set disabled ( value : any ) {
138- this . _disabled = coerceBooleanProperty ( value ) ;
115+ set disabled ( value : any ) {
116+ this . _disabled = value ;
139117 this . _updateRippleDisabled ( ) ;
140118 }
141119 private _disabled : boolean = false ;
142120
143121 constructor (
144- elementRef : ElementRef ,
122+ public _elementRef : ElementRef ,
145123 public _platform : Platform ,
146124 public _ngZone : NgZone ,
147125 public _animationMode ?: string ,
148126 ) {
149- super ( elementRef ) ;
150-
151127 this . _rippleLoader ?. configureRipple ( this . _elementRef . nativeElement , {
152128 className : 'mat-mdc-button-ripple' ,
153129 } ) ;
154130
155- const classList = ( elementRef . nativeElement as HTMLElement ) . classList ;
131+ const classList = ( _elementRef . nativeElement as HTMLElement ) . classList ;
156132
157133 // For each of the variant selectors that is present in the button's host
158134 // attributes, add the correct corresponding MDC classes.
@@ -195,9 +171,6 @@ export class MatButtonBase
195171 }
196172}
197173
198- /** Shared inputs by buttons using the `<a>` tag */
199- export const MAT_ANCHOR_INPUTS = [ 'disabled' , 'disableRipple' , 'color' , 'tabIndex' ] ;
200-
201174/** Shared host configuration for buttons using the `<a>` tag. */
202175export const MAT_ANCHOR_HOST = {
203176 '[attr.disabled]' : 'disabled || null' ,
@@ -215,13 +188,19 @@ export const MAT_ANCHOR_HOST = {
215188 // Add a class that applies to all buttons. This makes it easier to target if somebody
216189 // wants to target all Material buttons.
217190 '[class.mat-mdc-button-base]' : 'true' ,
191+ '[class]' : 'color ? "mat-" + color : ""' ,
218192} ;
219193
220194/**
221195 * Anchor button base.
222196 */
223197@Directive ( )
224198export class MatAnchorBase extends MatButtonBase implements OnInit , OnDestroy {
199+ @Input ( {
200+ transform : ( value : unknown ) => {
201+ return value == null ? undefined : numberAttribute ( value ) ;
202+ } ,
203+ } )
225204 tabIndex : number ;
226205
227206 constructor ( elementRef : ElementRef , platform : Platform , ngZone : NgZone , animationMode ?: string ) {
0 commit comments