Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Request: Method for closing the snackbar #1466

Closed
deap82 opened this issue Oct 24, 2017 · 2 comments · Fixed by #4166
Closed

Request: Method for closing the snackbar #1466

deap82 opened this issue Oct 24, 2017 · 2 comments · Fixed by #4166

Comments

@deap82
Copy link

deap82 commented Oct 24, 2017

Feature Request

When using the snack bar component in a SPA website, it would be useful if there was a method to call that would instantly hide (w/ animation) the snackbar (if it is currently showing) and remove any messages that might be in the queue. I would call this when the user navigates to a new view of the app and as such has decided messages from the current view are not of interest. Having messages shown/popup in the destination view just causes confusion.

@kfranqueiro
Copy link
Contributor

Thanks for filing this feature request. It does strike me as odd that we have an API for show but nothing for the opposite.

I also suspect it might be a good idea to provide both options - just hide the snackbar, or hide and clear its queue.

@thdk
Copy link

thdk commented Oct 14, 2018

I'm not sure but shouldn't this be done by the destroy method?

In your case, each view could have it's own snackbar which you destroy when the view is closed.
If you simply call HideAllSnackbars your code could still have async code triggering new snackbars for the closed view.

I though calling destroy would immediately remove all open snackbars and prevent new snackbars being shown. However, currently the only thing that happens when calling destroy is the eventHandler of the snackbar action button being removed.

But I can be very wrong with my idea of the destroy method.

A small example app with show and destroy implemented: https://typescript-jg9n7i.stackblitz.io
Note that you can still show snackbars when snackbar is destroyed.

acdvorak added a commit that referenced this issue Dec 13, 2018
### Issues fixed

* Fixes #4005 (via new `mdc-snackbar-viewport-margin()` mixin)
* Fixes #3981
* Fixes #2916 (via new `MDCSnackbar:closing` and `MDCSnackbar:closed` events)
* Fixes #2628
* Fixes #1466 (via new `close()` method)
* Fixes #1398
* Fixes #1258
* Fixes #11 (the label now expands indefinitely to fit the text)
* Refs #2813

### Screenshots

![Baseline without action button](https://user-images.githubusercontent.com/409245/49956261-a080ca80-feb9-11e8-8287-b7e805344115.png)

![Baseline with action button](https://user-images.githubusercontent.com/409245/49956109-4a138c00-feb9-11e8-9213-3241fa86a1b8.png)

![Stacked layout](https://user-images.githubusercontent.com/409245/49956173-6a434b00-feb9-11e8-8a03-2e58ccc8f763.png)

BREAKING CHANGE: Snackbar's DOM and APIs have changed to match the latest design guidelines. See the Snackbar documentation for more information.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants