Skip to content

Commit

Permalink
fix(snackbar): snacksbars sometimes don't get removed (#1795)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored Nov 10, 2016
1 parent 52e5cb5 commit fcd29c8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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

0 comments on commit fcd29c8

Please sign in to comment.