question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

extraClasses on snackBar doesn't work properly.

See original GitHub issue

Bug, 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

14reactions
moequraishicommented, Nov 21, 2017

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:

::ng-deep snack-bar-container.custom-class {
  background: yellow;
}

::ng-deep .custom-class .mat-simple-snackbar {
  color: green;
}
6reactions
markus-heinischcommented, Mar 2, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found