Skip to content
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

MdSnackBar does not close when MdDialog is closed #2190

Closed
jermowery opened this issue Dec 13, 2016 · 5 comments · Fixed by #2219
Closed

MdSnackBar does not close when MdDialog is closed #2190

jermowery opened this issue Dec 13, 2016 · 5 comments · Fixed by #2219
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@jermowery
Copy link
Contributor

jermowery commented Dec 13, 2016

Bug, feature request, or proposal:

Bug

What is the expected behavior?

MdSnackBar should be closed automatically when it's host MdDialog is destroyed or should be closable in ngOnDestroy.

What is the current behavior?

MdSnackBar remains open even after it's host MdDialog is destroyed. The SnackBar will be unresponsive with the buttons unclickable.

What are the steps to reproduce?

  1. Open an MdSnackBar from an MdDialog.
  2. Close the MdDialog

Plunker with the behavior: http://plnkr.co/edit/xrf3OSZec4J1w2MncFbY?p=preview

What is the use-case or motivation for changing an existing behavior?

Better user and developer experience

Which versions of Angular, Material, OS, browsers are affected?

Angular 2, Material 2

@crisbeto
Copy link
Member

All of the Material modules are intended to do be independent of each other. If we closed all of the toasts automatically when a dialog is closed, we'd make the dialog module dependent on the snack bar. You can achieve the same by subscribing to the dialog's close observable:

this.dialogRef = this.dialog.open(SomeDialog);

this.dialogRef.afterClosed().subscribe(result => {
  // close your snack bar
});

@jermowery
Copy link
Contributor Author

Here is a Plunker showing the issue: http://plnkr.co/edit/xrf3OSZec4J1w2MncFbY?p=preview

The component shown in the dialog is the component creating the snackbar

@jermowery
Copy link
Contributor Author

In the above example dismiss is called on the MdSnackBarRef instance in ngOnDestroy of the dialog component

@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Dec 13, 2016
@jelbourn
Copy link
Member

@crisbeto could you take a look at this one?

crisbeto added a commit to crisbeto/material2 that referenced this issue Dec 14, 2016
…troyed

Fixes the snack bar not being removed from the DOM when it's associated `viewContainerRef` gets destroyed.

Fixes angular#2190.
jelbourn pushed a commit that referenced this issue Dec 14, 2016
…troyed (#2219)

* fix(snack-bar): clean up element when associated viewContainer is destroyed

Fixes the snack bar not being removed from the DOM when it's associated `viewContainerRef` gets destroyed.

Fixes #2190.

* Fix bad formatting.

* Rename the cleanup method.
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants