Skip to content

Commit b3f8a42

Browse files
devversionjelbourn
authored andcommitted
fix(button): accent color not set on fab buttons with build optimizer (#9376)
When running an Angular application in production mode with the build optimizer and the Angular CLI, the code part, that sets the default color for round buttons, is removed accidentally. This seems to be an issue, that's caused by the build optimizer: angular/devkit#388. Fixes #9360
1 parent 8430617 commit b3f8a42

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

src/demo-app/button/button-demo.html

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22
<section>
33
<button mat-button>flat</button>
44
<button mat-raised-button>raised</button>
5-
<button mat-fab>
6-
<mat-icon>check</mat-icon>
7-
</button>
8-
<button mat-fab>Btn</button>
9-
<a mat-fab routerLink=".">Link</a>
5+
6+
<button mat-fab><mat-icon>check</mat-icon></button>
7+
<button mat-fab color="primary">Btn</button>
8+
<a mat-fab color="warn" routerLink=".">Link</a>
109
<a mat-fab routerLink="."><mat-icon>check</mat-icon></a>
11-
<button mat-mini-fab>
12-
<mat-icon>check</mat-icon>
13-
</button>
14-
<button mat-mini-fab>Btn</button>
15-
<a mat-mini-fab routerLink=".">Link</a>
10+
11+
<button mat-mini-fab><mat-icon>check</mat-icon></button>
12+
<button mat-mini-fab color="primary">Btn</button>
13+
<a mat-mini-fab color="warn" routerLink=".">Link</a>
14+
<a mat-mini-fab routerLink="."><mat-icon>check</mat-icon></a>
1615
</section>
1716

1817
<section>

src/lib/button/button.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@ import {
1313
Component,
1414
Directive,
1515
ElementRef,
16-
forwardRef,
17-
Inject,
1816
OnDestroy,
19-
Optional,
20-
Self,
2117
ViewEncapsulation,
2218
} from '@angular/core';
2319
import {
@@ -74,30 +70,17 @@ export class MatIconButtonCssMatStyler {}
7470
selector: 'button[mat-fab], a[mat-fab]',
7571
host: {'class': 'mat-fab'}
7672
})
77-
export class MatFab {
78-
constructor(@Self() @Optional() @Inject(forwardRef(() => MatButton)) button: MatButton,
79-
@Self() @Optional() @Inject(forwardRef(() => MatAnchor)) anchor: MatAnchor) {
80-
// Set the default color palette for the mat-fab components.
81-
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
82-
}
83-
}
73+
export class MatFab {}
8474

8575
/**
86-
* Directive that targets mini-fab buttons and anchors. It's used to apply the `mat-` class
87-
* to all mini-fab buttons and also is responsible for setting the default color palette.
76+
* Directive whose purpose is to add the mat- CSS styling to this selector.
8877
* @docs-private
8978
*/
9079
@Directive({
9180
selector: 'button[mat-mini-fab], a[mat-mini-fab]',
9281
host: {'class': 'mat-mini-fab'}
9382
})
94-
export class MatMiniFab {
95-
constructor(@Self() @Optional() @Inject(forwardRef(() => MatButton)) button: MatButton,
96-
@Self() @Optional() @Inject(forwardRef(() => MatAnchor)) anchor: MatAnchor) {
97-
// Set the default color palette for the mat-mini-fab components.
98-
(button || anchor).color = DEFAULT_ROUND_BUTTON_COLOR;
99-
}
100-
}
83+
export class MatMiniFab {}
10184

10285

10386
// Boilerplate for applying mixins to MatButton.
@@ -139,7 +122,12 @@ export class MatButton extends _MatButtonMixinBase
139122
private _platform: Platform,
140123
private _focusMonitor: FocusMonitor) {
141124
super(elementRef);
125+
142126
this._focusMonitor.monitor(this._elementRef.nativeElement, true);
127+
128+
if (this._isRoundButton) {
129+
this.color = DEFAULT_ROUND_BUTTON_COLOR;
130+
}
143131
}
144132

145133
ngOnDestroy() {

0 commit comments

Comments
 (0)