Skip to content

fix(material/core): special-case icon button color token #31625

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2025

Conversation

andrewseguin
Copy link
Contributor

@andrewseguin andrewseguin commented Jul 30, 2025

Normally, an icon button should automatically get its color from whatever container it's placed in. This is important so the icon always has the right contrast to be visible, whether it's on a light, dark, or colored background.

However, when the icon button's M2 color token is inherit, the browser will always use the fallback color on-surface-variant which is going to now be defined in this mixin.

To fix this, this code directly sets the icon's color and makes sure no fallback is defined. This forces the icon to correctly inherit its color from the container as originally intended.

Also: adds the mixin to the dev-app theme

@andrewseguin andrewseguin requested a review from a team as a code owner July 30, 2025 19:34
@andrewseguin andrewseguin requested review from wagnermaciel and ok7sai and removed request for a team July 30, 2025 19:34
@andrewseguin andrewseguin added the target: minor This PR is targeted for the next minor release label Jul 30, 2025
@andrewseguin andrewseguin requested a review from crisbeto July 30, 2025 22:48
@@ -23,6 +23,7 @@ $candy-app-theme: mat.m2-define-light-theme((

@include mat.app-background();
@include mat.elevation-classes();
@include mat.m2-theme($candy-app-theme);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have this if there's also another theme?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only defines the system vars - I'd like to make a dev-app page that shows all the variables and this makes that work for both M2 and M3. This mixin, unlike M3, isn't meant to be a replacement for the individual component mixins

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus this helps validate that nothing changes on the site if it's included. This is how I found the issue with the icon button's styles.

Part of this is to encourage people to use this mixin and use systems vars instead of our m2 APIs to pull from the theme config. If we find an issue in the dev-app from this, we should fix it

@@ -350,6 +350,21 @@

@include _define-m2-system-vars(m2.md-sys-shape-values(), $overrides);
@include _define-m2-system-vars(m2.md-sys-state-values(), $overrides);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is in system.scss, does it mean that we'll generate the concrete styles next to token styles?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the icon button? Yeah unfortunately. I thought about adding a modification in icon-button's theme mixin but that introduces the same sort of issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we at least have a @if (isM2) around it so it doesn't affect M3?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is specifically an M2-only mixin, different entirely from the implementation for @mixin theme.

This mixin explicitly takes an M2 theme config and is meant to convert that to system CSS vars. I don't expect M3 apps to ever call this

@andrewseguin andrewseguin added the action: merge The PR is ready for merge by the caretaker label Jul 31, 2025
@andrewseguin andrewseguin merged commit 7674e58 into angular:main Jul 31, 2025
23 of 25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: material/core target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants