File tree 2 files changed +21
-1
lines changed
2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -219,6 +219,23 @@ describe('MdSnackBar', () => {
219
219
} ) ;
220
220
} ) ;
221
221
} ) ) ;
222
+
223
+ it ( 'should remove past snackbars when opening new snackbars' , async ( ( ) => {
224
+ snackBar . open ( 'First snackbar' ) ;
225
+ viewContainerFixture . detectChanges ( ) ;
226
+
227
+ snackBar . open ( 'Second snackbar' ) ;
228
+ viewContainerFixture . detectChanges ( ) ;
229
+
230
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
231
+ snackBar . open ( 'Third snackbar' ) ;
232
+ viewContainerFixture . detectChanges ( ) ;
233
+
234
+ viewContainerFixture . whenStable ( ) . then ( ( ) => {
235
+ expect ( overlayContainerElement . textContent . trim ( ) ) . toBe ( 'Third snackbar' ) ;
236
+ } ) ;
237
+ } ) ;
238
+ } ) ) ;
222
239
} ) ;
223
240
224
241
@Directive ( { selector : 'dir-with-view-container' } )
Original file line number Diff line number Diff line change @@ -48,7 +48,10 @@ export class MdSnackBar {
48
48
49
49
// When the snackbar is dismissed, clear the reference to it.
50
50
snackBarRef . afterDismissed ( ) . subscribe ( ( ) => {
51
- this . _snackBarRef = null ;
51
+ // Clear the snackbar ref if it hasn't already been replaced by a newer snackbar.
52
+ if ( this . _snackBarRef == snackBarRef ) {
53
+ this . _snackBarRef = null ;
54
+ }
52
55
} ) ;
53
56
54
57
// If a snack bar is already in view, dismiss it and enter the new snack bar after exit
You can’t perform that action at this time.
0 commit comments