mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
fix(snackbar): always clear ref when dismissing (#1773)
This commit is contained in:
@@ -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'})
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user