Skip to content

Commit

Permalink
fix(snackbar): always clear ref when dismissing (#1773)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored Nov 8, 2016
1 parent 2b913de commit 3c5b632
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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'})
Expand Down
5 changes: 5 additions & 0 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3c5b632

Please sign in to comment.