extraClasses on snackBar doesn't work properly.
See original GitHub issueBug, feature request, or proposal:
Bug
What is the expected behavior?
When I supply a CSS class to snackbar via the extraClasses property, it should apply that class.
What is the current behavior?
The styles defined in that class are all overridden by other material styling.
What are the steps to reproduce?
In styles.css
:
.success-snackbar{
background-color: #FFF;
color: #AAA;
}
In my component:
this.snackBar.open("Hey", undefined, {
duration: 90000,
extraClasses: ['success-snackbar']
});
The class IS being applied when I look at it in the inspector, but both color
and background-color
are being overriden by other material styling.
What is the use-case or motivation for changing an existing behavior?
It isn’t working.
Which versions of Angular, Material, OS, TypeScript, browsers are affected?
Angular 4.0.1 Material 2.0.0-beta.2 OS: macOS 10.12.4 Typescript: 2.2.2 Browsers: Chrome, Safari
Is there anything else we should know?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:19 (3 by maintainers)
Top Results From Across the Web
Material SnackBar extraClasses doesn't seem to be working
My main stumbling block is two-fold: First: I am struggling implement the extraClasses property. I've tried passing existing snack-bar classes ...
Read more >Snackbars - Material Design
Snackbars. Snackbars provide brief messages about app processes at the bottom of the screen. design_services Design integration_instructions Implementation.
Read more >Snackbar - Angular Material
Extra CSS classes to be added to the snack bar container. politeness: AriaLivePoliteness. The politeness level for the MatAriaLiveAnnouncer announcement.
Read more >SnackBar class - material library - Flutter - Dart API docs
SnackBar class Null safety. A lightweight message with an optional action which briefly displays at the bottom of the screen. If playback doesn't...
Read more >Snackbars in React: An Exercise in Hooks and Context
Sign up for Medium and get an extra one ... This function uses the local state mutator useState to properly append a new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Update for OP:
I got this to work using an answer I found on StackOverflow: StackOverflow
You had everything right, just had to specify the css classes properly:
Thanks @moequraishi . Here is my solution for a snackbar that has two different styles depending on online/offline connection. First, my component code:
const snackBarRef = this.snackBar.open(message, "Close", { duration: 3000, panelClass: isOnline ? ["online", "onlineAction"] : "offline" });
Component CSS:::ng-deep .mat-snack-bar-container.offline { background: #c00003; } ::ng-deep .mat-snack-bar-container.online { background: #57c54d; }
One issues is not solved: How can I the color of the action button? I can change the text color of the message but the text color of the action stays white. Adding a color like
color: rgba(243, 10, 10, 0.87);
to my CSS definitions does not help.