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

fix(snackbar): snacksbars sometimes don't get removed #1795

Merged
merged 1 commit into from
Nov 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,23 @@ describe('MdSnackBar', () => {
});
});
}));

it('should remove past snackbars when opening new snackbars', async(() => {
snackBar.open('First snackbar');
viewContainerFixture.detectChanges();

snackBar.open('Second snackbar');
viewContainerFixture.detectChanges();

viewContainerFixture.whenStable().then(() => {
snackBar.open('Third snackbar');
viewContainerFixture.detectChanges();

viewContainerFixture.whenStable().then(() => {
expect(overlayContainerElement.textContent.trim()).toBe('Third snackbar');
});
});
}));
});

@Directive({selector: 'dir-with-view-container'})
Expand Down
5 changes: 4 additions & 1 deletion src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ export class MdSnackBar {

// When the snackbar is dismissed, clear the reference to it.
snackBarRef.afterDismissed().subscribe(() => {
this._snackBarRef = null;
// Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
if (this._snackBarRef == snackBarRef) {
this._snackBarRef = null;
}
});

// If a snack bar is already in view, dismiss it and enter the new snack bar after exit
Expand Down