Skip to content

Commit 7b85cc0

Browse files
crisbetoandrewseguin
authored andcommitted
fix(material-experimental/mdc-button): density styles being overwritten by structural styles (#22736)
The button's density styles currently have the same specificity as the structural styles which means that they'll usually be overwritten, unless they're nested inside another selector. These changes add more specificity so that the density always has precedence. Fixes #22728. (cherry picked from commit 3021cf5)
1 parent d496ff3 commit 7b85cc0

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,11 @@
196196
.mat-mdc-raised-button,
197197
.mat-mdc-unelevated-button,
198198
.mat-mdc-outlined-button {
199-
@include mdc-button-theme.density($density-scale, $query: mdc-helpers.$mat-base-styles-query);
200-
@include button-theme-private.touch-target-density($density-scale);
199+
// Use `mat-mdc-button-base` to increase the specificity over the button's structural styles.
200+
&.mat-mdc-button-base {
201+
@include mdc-button-theme.density($density-scale, $query: mdc-helpers.$mat-base-styles-query);
202+
@include button-theme-private.touch-target-density($density-scale);
203+
}
201204
}
202205
}
203206

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949

5050
@mixin density($config-or-theme) {
5151
$density-scale: theming.get-density-config($config-or-theme);
52-
.mat-mdc-icon-button {
52+
// Use `mat-mdc-button-base` to increase the specificity over the button's structural styles.
53+
.mat-mdc-icon-button.mat-mdc-button-base {
5354
@include mdc-icon-button.density($density-scale, $query: mdc-helpers.$mat-base-styles-query);
5455
@include button-theme-private.touch-target-density($density-scale);
5556
}

0 commit comments

Comments
 (0)