Skip to content

Commit b049b8d

Browse files
authored
fix(material/button): fix icon button density (#26877)
* fix(material/button): fix icon button density * fix(material/button): fix icon button density
1 parent 70b504b commit b049b8d

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

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

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
@use '../core/tokens/m2/mdc/icon-button' as tokens-mdc-icon-button;
77

88
@use './button-theme-private';
9-
@use '../core/mdc-helpers/mdc-helpers';
109
@use '../core/theming/theming';
11-
@use '../core/typography/typography';
10+
11+
$_icon-size: 24px;
1212

1313
@mixin _ripple-color($color) {
1414
--mat-mdc-button-persistent-ripple-color: #{$color};
@@ -23,7 +23,6 @@
2323
@return if($is-dark, 'light', 'dark');
2424
}
2525

26-
2726
@mixin color($config-or-theme) {
2827
$config: theming.get-color-config($config-or-theme);
2928
$color-tokens: tokens-mdc-icon-button.get-color-tokens($config);
@@ -66,35 +65,45 @@
6665
}
6766

6867
@mixin typography($config-or-theme) {
69-
$config: typography.private-typography-to-2018-config(
70-
theming.get-typography-config($config-or-theme));
71-
@include mdc-helpers.using-mdc-typography($config) {
72-
@include mdc-icon-button.without-ripple($query: mdc-helpers.$mdc-typography-styles-query);
73-
}
7468
}
7569

7670
@mixin density($config-or-theme) {
7771
$density-scale: theming.get-density-config($config-or-theme);
78-
79-
.mat-mdc-icon-button {
80-
// Manually apply the expected density theming, and include the padding
81-
// as it was applied before
82-
$calculated-size: mdc-density-functions.prop-value(
83-
$density-config: (
84-
size: (
85-
default: 48px,
86-
maximum: 48px,
87-
minimum: 28px,
88-
),
72+
// Manually apply the expected density theming, and include the padding
73+
// as it was applied before
74+
$calculated-size: mdc-density-functions.prop-value(
75+
$density-config: (
76+
size: (
77+
default: 48px,
78+
maximum: 48px,
79+
minimum: 28px,
8980
),
90-
$density-scale: $density-scale,
91-
$property-name: size,
92-
);
81+
),
82+
$density-scale: $density-scale,
83+
$property-name: size,
84+
);
9385

86+
.mat-mdc-icon-button {
9487
@include mdc-icon-button-theme.theme((
9588
state-layer-size: $calculated-size,
9689
));
9790
}
91+
92+
// Use `mat-mdc-button-base` to increase the specificity over the button's structural styles.
93+
.mat-mdc-icon-button.mat-mdc-button-base {
94+
// Match the styles that used to be present. This is necessary for backwards
95+
// compat to match the previous implementations selector count (two classes).
96+
// TODO: Switch calculated-size to "var(--mdc-icon-button-state-layer-size)"
97+
// Currently fails validation because the variable is "undefined"
98+
// in the sass stack.
99+
// TODO: Switch icon-size to "var(--mdc-icon-button-icon-size)". Currently
100+
// fails validation because the variable is "undefined" in the sass stack.
101+
width: var(--mdc-icon-button-state-layer-size);
102+
height: var(--mdc-icon-button-state-layer-size);
103+
padding: ($calculated-size - $_icon-size) / 2;
104+
105+
@include button-theme-private.touch-target-density($density-scale);
106+
}
98107
}
99108

100109
@mixin theme($theme-or-color-config) {

src/material/core/tokens/m2/mdc/_icon-button.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ $prefix: (mdc, icon-button);
4343
pressed-icon-color: null,
4444
pressed-state-layer-color: null,
4545
pressed-state-layer-opacity: null,
46-
4746
);
4847
}
4948

0 commit comments

Comments
 (0)