-
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
feat(snack-bar): allow addition of extra css classes #2804
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Allows users to add extra CSS classes to the snack bar container via the `extraClasses` option. Fixes angular#2664.
4be9495
to
e165846
Compare
hello! this would be really useful to me ... I see that is not yet included in npm, when will it be? it's not clear to me current release policy, sorry. |
@giona69 it should be in the text release. If you don't want to wait until then, you can install the code from |
oh great! thanks so much! |
This feature should be very useful and make the snack bar to the total customization.
|
Is it released yet ? |
Yes, it had released in newest version. |
I guess it's not in the document yet. |
Docs is missing styling customization, how I can change font and bg color? Thanks! |
@aelkz You're now able to add custom classes to the snack-bar-container element, which you can target and style with CSS in the usual way. To do that, you list the extra classes in an array assigned to the extraClasses property, which is passed in your configuration when opening a snack-bar. For example:
|
can anyone give one working example for changing message color and specifying action in snackbar |
this is not working! |
@benishak I am using precisely that code in my own application, which is working absolutely fine. Your implementation may not work, for whatever reason. But I can assure you that "it" is indeed "working". |
that's weird, i tried too many possibilities ... here is my code :host /deep/ snack-bar-container .success {
background-color: #00ff7f !important;
}
:host /deep/ snack-bar-container .error {
background-color: #b24747 !important;
} I also tried without And Component showSnackBar(message: string, action: string, stat?: string) {
let config = new MdSnackBarConfig();
config.duration = 2000;
if (stat) config.extraClasses = [stat];
this.snackBar.open(message, action, config);
} I'm using Materials |
@benishak Is the class at least being added to your html? Can you confirm it's present using your browser's dev tools? Try simply targeting the class name in your CSS. For example, name the class something less generic (to avoid clashes), such as snackbar-success, then in your CSS:
|
After checking I cannot see the css in the browser ... although I have in the same component css other styles and they are working fine |
be careful about where you put the css class. if you put the css class in the app-name.component.css file, the css selector is rewritten by angular to .class-name[_ngcontent-c0]. if you put the css class in a separate file and then include it in the index.html page via a link tag the selector does not change and the class will be applied to your element. the issue, in this case, is that the snack-bar element does not include the _ngcontent-c0 attribute. |
Need to use Initially was struggling to style the action button but here it is hope it will help to someone else:
|
for newbs like me: if this isn't working, make sure your css class is using :ng-deep, like this: `::ng-deep snack-bar-container.custom-class { ::ng-deep .custom-class .mat-simple-snackbar { found here |
All above options doesn-t work, but this works for me, @import '../node_modules/@angular/material/_theming.scss';
@include mat-core();
$background-primary: #232323;
$background-accent: #353535;
$background-warn: #c1640c;
$font-color-default: silver;
$my-app-primary: mat-palette($mat-light-green, 700);
$my-app-accent: mat-palette($mat-cyan, 800 );
$my-app-warn: mat-palette($mat-red, 400);
$my-app-theme: mat-dark-theme($my-app-primary, $my-app-accent, $my-app-warn);
@mixin snack-theme($theme) {
// Extract whichever individual palettes you need from the theme.
$primary: map-get($theme, primary);
$accent: map-get($theme, accent);
$warn: map-get($theme, warn);
.mat-snack-bar-container {
background-color: $background-accent !important;
color: $font-color-default;
}
//Added with panelClass property
.snack-error {
button {
color: mat-color($warn)
}
}
//Added with panelClass property
.snack-success {
button {
color: mat-color($primary)
}
}
}
@include snack-theme($my-app-theme); |
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. |
Allows users to add extra CSS classes to the snack bar container via the
extraClasses
option.Fixes #2664.