Skip to content

bug(icon-button): The backwards compatability mixin for color variants is not affecting icon buttons #29146

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

Closed
cuzo989874 opened this issue May 30, 2024 · 8 comments
Assignees
Labels
area: material/button area: theming P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@cuzo989874
Copy link

Documentation Feedback

In the previous version (Angular/Material 17), the color of the mat-icon-button could be customized. However, I am currently unable to access the code or obtain the correct demo version, even though the parameter still exists on the API page.

image

Affected documentation page

https://material.angular.io/components/button/overview#button-overview

@cuzo989874 cuzo989874 added docs This issue is related to documentation needs triage This issue needs to be triaged by the team labels May 30, 2024
@cuzo989874 cuzo989874 changed the title docs-bug(COMPONENT): mat-icon-button can not be custom color docs-bug(mat-button): mat-icon-button can not be custom color Jun 3, 2024
@amysorto
Copy link
Contributor

amysorto commented Jun 3, 2024

Thanks for pointing this out! In M3, you need to use a backwards compatability mixin to get that same code to work. See our docs for how to use it. Let me know if that solves this issue for you!

I'll update this issue to track removing the color inputs for the component specific documentation.

@amysorto amysorto changed the title docs-bug(mat-button): mat-icon-button can not be custom color docs(all): Remove color input from component specific documentation since not part of M3 without backwards compatibility mixin Jun 3, 2024
@amysorto amysorto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: many Area label for issues related to many components and removed needs triage This issue needs to be triaged by the team labels Jun 3, 2024
@cuzo989874
Copy link
Author

cuzo989874 commented Jun 4, 2024

Thanks for pointing this out! In M3, you need to use a backwards compatability mixin to get that same code to work. See our docs for how to use it. Let me know if that solves this issue for you!

I'll update this issue to track removing the color inputs for the component specific documentation.

I understand that we should use the backwards compatibility mixin for setting the theme. However, the issue is that the mat-icon-button appears to be an exception; its color cannot be set. You can identify this problem by looking through the docs, specifically in the icon section.

Honesty, I already setup M3 system with custom theme in my workspace, but only mat-icon-button still cannot be setting color and I found that official demo cannot either, that's why I coming.

@banut1
Copy link

banut1 commented Jun 5, 2024

Check this: #29151.

Starting from that answer, here's what I did and works well:

For a primary icon button, I defined:

 .mat-mdc-icon-button.primary:not(:disabled) {
  @include mat.icon-color($theme, $color-variant: primary);
  @include mat.icon-button-color($theme);
}

For a warn one, I defined a whole warn theme and similarly to the above, a class .warn. It works well and does not use the m2 color attributes at all, neither the backwards compatibility mixin.

Usage:
<button mat-icon-button class="primary">...</button>

Hope it helps!

@midthun
Copy link

midthun commented Jun 5, 2024

Not sure if 100% related, but I think it is:

Found it a bit confusing in the API section when trying to style my mat-selection-list: https://material.angular.io/components/list/api

The color does nothing when you add it to options or lists, but it is there in the documentation. Also, it only accepts m2 colors, like primary, accent etc, but still does nothing when used in m3.

@amysorto
Copy link
Contributor

@cuzo989874 Thanks for pointing out that the icon-button variant is missing. I took a closer look and yes that example does have the backwards compatability mixin but it isn't affecting icon buttons. I'll change the title for this issue accordingly.

In the meantime, you can add custom styles for your icon buttons if necessary or do what @banut1 suggested. The CSS variable --mat-icon-color is how you can change the color. For example if you want to change the warn icon buttons you can do the following:

.mdc-icon-button.mat-warn {
  --mat-icon-color: $your-color;
}

Note: You can also directly access the color roles from the theme itself with mat.get-theme-color. So in the example above you can do --mat-icon-color: mat.get-theme-color($your-theme, $error);

@midthun I agree, we are updating our docs for the different components page to make this more clear. Thanks!

@amysorto amysorto added area: material/button area: theming and removed docs This issue is related to documentation area: many Area label for issues related to many components labels Jun 13, 2024
@amysorto amysorto changed the title docs(all): Remove color input from component specific documentation since not part of M3 without backwards compatibility mixin bug(icon-button): The backwards compatability mixin for color variants is not affecting icon buttons Jun 13, 2024
@cuzo989874
Copy link
Author

cuzo989874 commented Jun 18, 2024

Here is my temporary solution. If anyone has the same situation, you can follow this:

:root {
    .mat-primary {
        --mdc-icon-button-icon-color: #{variables.$primary-color};
        --mat-icon-button-state-layer-color: #{map.get(palette.$primary, 70)};
    }
    .mat-accent {
        --mdc-icon-button-icon-color: #{variables.$accent-color};
        --mat-icon-button-state-layer-color: #{map.get(palette.$tertiary, 70)};
    }
    .mat-warn {
        --mdc-icon-button-icon-color: #{variables.$error-color};
        --mat-icon-button-state-layer-color: #{map.get(map.get(palette.$primary, error), 70)};
    }
}

@crisbeto
Copy link
Member

This was fixed by #29433.

@crisbeto crisbeto self-assigned this Jul 24, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/button area: theming P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests

5 participants