-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
bug(snack-bar): action button color not changeable #27328
Comments
Hello! After a thorough investigation, I have identified that the issue originates from the following CSS code in the // The `mat-mdc-button` and `:not(:disabled)` here are redundant, but I need them to increase
// the specificity over the button styles that may bleed in from the rest of the app.
.mat-mdc-button.mat-mdc-snack-bar-action:not(:disabled) {
// MDC's `action-label-text-color` should be able to do this, but the button theme has a
// higher specificity so it ends up overriding it. I defined my own variable that I can
// use to control the color instead. In an effort to resolve the problem, I experimented with adding the following CSS, which seems to effectively address the concern and display the button in the desired color: .mat-mdc-button.mat-mdc-snack-bar-action:not(:disabled) :not([color]) { Although my proposed solution appears to work as intended, I am uncertain if it aligns with best practices. |
I would like to add here that you don't necessarily have to create a custom snackbar component in order to experience this issue. Since Angular 15 we can override scss variables in order to change the desired styles. For instance: openSnackbar() {
this.snackBar.open(message, 'X', {
panelClass: ['success-snackbar '],
verticalPosition: 'top',
horizontalPosition: 'center',
});
} global CSS (styles.scss): .mat-mdc-snack-bar-container {
&.success-snackbar {
--mdc-snackbar-container-color: green;
--mat-mdc-snack-bar-container: red;
--mdc-snackbar-supporting-text-color: blue;
}
} The following snipets result in: As seen from the screenshot the I have attached the broken stackblitz (Angular 17.0.0 but reproducible in 16.2.x as well) - https://stackblitz.com/edit/ptc6zb?file=src%2Fstyles.scss,src%2Fexample%2Fsnack-bar-overview-example.ts It would appear that @json-derulo 's PR #27511 might fix the issue |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Is this a regression?
The previous version in which this bug was not present was
14
Description
I have a snack bar with a custom component. In this component I have a custom action button. I want this button to be in the primary color, so I set the
color
attribute of the button to"primary"
:Before MDC, the
color
attribute was respected, and the button changed its color accordingly. After MDC migration, the button stays in the accent color regardless of whatcolor
is set.Reproduction
StackBlitz link: https://stackblitz.com/edit/kbv7nf
Steps to reproduce:
color
of the action button to"primary"
Expected Behavior
The button is displayed in the primary color
Actual Behavior
The button is displayed in the accent color
Environment
Further notes
I investigated the issue a bit, and it seems like using the
matSnackBarAction
directive overrides the color of the button. Omitting this directive fixes the issue, however the docs state that this directive should be used.The text was updated successfully, but these errors were encountered: