fix(snackbar): always clear ref when dismissing (#1773)

This commit is contained in:
Jeremy Elbourn
2016-11-08 14:22:31 -08:00
committed by GitHub
parent 2b913de34d
commit 3c5b632b13
2 changed files with 27 additions and 13 deletions
+22 -13
View File
@@ -1,16 +1,5 @@
import {
inject,
async,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import {
NgModule,
Component,
Directive,
ViewChild,
ViewContainerRef
} from '@angular/core';
import {inject, async, ComponentFixture, TestBed} from '@angular/core/testing';
import {NgModule, Component, Directive, ViewChild, ViewContainerRef} from '@angular/core';
import {MdSnackBar, MdSnackBarModule} from './snack-bar';
import {OverlayContainer, MdLiveAnnouncer} from '../core';
import {MdSnackBarConfig} from './snack-bar-config';
@@ -194,6 +183,26 @@ describe('MdSnackBar', () => {
.toBe('visible', `Expected the animation state would be 'visible'.`);
});
}));
it('should open a new snackbar after dismissing a previous snackbar', async(() => {
let config = new MdSnackBarConfig(testViewContainerRef);
let snackBarRef = snackBar.open(simpleMessage, 'DISMISS', config);
viewContainerFixture.detectChanges();
snackBarRef.dismiss();
viewContainerFixture.detectChanges();
// Wait for the snackbar dismiss animation to finish.
viewContainerFixture.whenStable().then(() => {
snackBarRef = snackBar.open('Second snackbar', 'DISMISS', config);
viewContainerFixture.detectChanges();
// Wait for the snackbar open animation to finish.
viewContainerFixture.whenStable().then(() => {
expect(snackBarRef.containerInstance.animationState).toBe('visible');
});
});
}));
});
@Directive({selector: 'dir-with-view-container'})
+5
View File
@@ -45,6 +45,11 @@ export class MdSnackBar {
let snackBarContainer = this._attachSnackBarContainer(overlayRef, config);
let mdSnackBarRef = this._attachSnackbarContent(component, snackBarContainer, overlayRef);
// When the snackbar is dismissed, clear the reference to it.
mdSnackBarRef.afterDismissed().subscribe(() => {
this._snackBarRef = null;
});
// If a snack bar is already in view, dismiss it and enter the new snack bar after exit
// animation is complete.
if (this._snackBarRef) {