Skip to content

Commit 7674e58

Browse files
andrewseguinAndrew Seguin
andauthored
fix(material/core): special-case icon button color token (#31625)
* fix(material/core): special-case icon button color token * fix(material/core): remove [disabled] * fix(material/core): add validation against m3 theme configs --------- Co-authored-by: Andrew Seguin <[email protected]>
1 parent ab26231 commit 7674e58

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/dev-app/theme.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ $candy-app-theme: mat.m2-define-light-theme((
2323

2424
@include mat.app-background();
2525
@include mat.elevation-classes();
26+
@include mat.m2-theme($candy-app-theme);
2627

2728
// Include the default theme styles.
2829
@include mat.all-component-themes($candy-app-theme);
@@ -58,6 +59,7 @@ $candy-app-theme: mat.m2-define-light-theme((
5859
typography: mat.m2-define-typography-config(),
5960
)
6061
);
62+
@include mat.m2-theme($dark-colors);
6163

6264
// Include the dark theme color styles.
6365
@include mat.all-component-colors($dark-colors);

src/material/core/tokens/_system.scss

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@use '../style/elevation';
1919
@use '../theming/config-validation';
2020
@use '../theming/definition';
21+
@use '../theming/inspection';
2122
@use '../theming/m2-inspection';
2223
@use '../theming/palettes';
2324
@use '../style/sass-utils';
@@ -322,6 +323,11 @@
322323
// Unlike M3's `mat.theme()`, this mixin does not replace the need to call
323324
// individual component theme mixins for Angular Material components.
324325
@mixin m2-theme($theme-config, $overrides: ()) {
326+
@if inspection.get-theme-version($theme-config) == 1 {
327+
@error '`m2-theme` mixin should only be called for M2 theme ' +
328+
'configs created with define-light-theme or define-dark-theme';
329+
}
330+
325331
$config: m2-inspection.get-m2-config($theme-config);
326332

327333
$color: map.get($config, color);
@@ -350,6 +356,18 @@
350356

351357
@include _define-m2-system-vars(m2.md-sys-shape-values(), $overrides);
352358
@include _define-m2-system-vars(m2.md-sys-state-values(), $overrides);
359+
360+
// The icon button's color token is set to `inherit` for M2 and intended to display
361+
// the color inherited from its parent element. This is crucial because it's unknown
362+
// whether the icon button sits on a container with background like "surface" or "primary",
363+
// where both may have different contrast colors like white or black.
364+
// However, variables set to inherit AND define a fallback will always use the fallback,
365+
// which is "on-surface-variant". This mixin now defines this value.
366+
// To avoid this, and continue using `inherit` for the icon button color, set the color explicitly
367+
// to the token without a fallback.
368+
.mat-mdc-button-base.mat-mdc-icon-button:not(.mat-mdc-button-disabled) {
369+
color: var(--mat-icon-button-icon-color);
370+
}
353371
}
354372

355373
@mixin _define-m2-system-vars($vars, $overrides) {

0 commit comments

Comments
 (0)