Skip to content

Commit 61deb71

Browse files
annieywandrewseguin
authored andcommitted
fix(material-experimental/mdc-button): use mdc mixins to style icons within buttons (#21623)
* fix(material-experimental/mdc-button): use mdc mixins to style icons within buttons * fix(material-experimental/mdc-button): fix icon size for unelevated, raised, and outlined (cherry picked from commit a96fbc6)
1 parent a30f656 commit 61deb71

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/material-experimental/mdc-button/button.scss

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@use '@material/button/button';
2+
13
@import '@material/button/mixins.import';
24
@import '@material/button/variables.import';
35
@import '@material/ripple/mixins.import';
@@ -10,20 +12,32 @@
1012
.mat-mdc-button, .mat-mdc-unelevated-button, .mat-mdc-raised-button, .mat-mdc-outlined-button {
1113
@include mat-private-button-interactive();
1214
@include mat-private-button-disabled();
15+
}
16+
17+
// MDC expects button icons to contain this HTML content:
18+
// ```html
19+
// <span class="mdc-button__icon material-icons">favorite</span>
20+
// ```
21+
// However, Angular Material expects a `mat-icon` instead. The following
22+
// mixins will style the icons appropriately.
23+
.mat-mdc-button {
24+
.mat-icon {
25+
@include button.icon();
26+
}
27+
.mdc-button__label + .mat-icon {
28+
@include button.icon-trailing();
29+
}
30+
}
1331

14-
// MDC expects button icons to contain this HTML content:
15-
// ```html
16-
// <span class="mdc-button__icon material-icons">favorite</span>
17-
// ```
18-
// However, Angular Material expects a `mat-icon` instead. The following
19-
// will extend the `mdc-button__icon` styling to the mat icon. Note that
20-
// the extended styles inherently only match icons that nest themselves in
21-
// a parent `mdc-button`.
22-
//
23-
// TODO(mmalerba): Have MDC create a mixin for this so we don't have to rely on extending their
24-
// class.
32+
.mat-mdc-unelevated-button, .mat-mdc-raised-button, .mat-mdc-outlined-button {
33+
// Icons inside contained buttons have different styles due to increased button padding
2534
.mat-icon {
26-
@extend .mdc-button__icon;
35+
@include button.icon();
36+
@include button.icon-contained();
37+
}
38+
39+
.mdc-button__label + .mat-icon {
40+
@include button.icon-contained-trailing();
2741
}
2842
}
2943

0 commit comments

Comments
 (0)