Skip to content

Commit

Permalink
fix(snackbar): remove even if still animating open (#1797)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored Nov 10, 2016
1 parent fcd29c8 commit 523a48e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/lib/snack-bar/snack-bar-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ export class MdSnackBarContainer extends BasePortalHost {

/** Mark snack bar as exited from the view. */
markAsExited(event: AnimationTransitionEvent) {
if (event.fromState === 'visible' &&
(event.toState === 'void' || event.toState === 'complete')) {
if (event.toState === 'void' || event.toState === 'complete') {
this._ngZone.run(() => {
this._onExit.next();
this._onExit.complete();
Expand Down
25 changes: 24 additions & 1 deletion src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import {inject, async, ComponentFixture, TestBed} from '@angular/core/testing';
import {
inject,
async,
ComponentFixture,
TestBed,
fakeAsync,
flushMicrotasks,
tick,
} from '@angular/core/testing';
import {NgModule, Component, Directive, ViewChild, ViewContainerRef} from '@angular/core';
import {MdSnackBar, MdSnackBarModule} from './snack-bar';
import {OverlayContainer, MdLiveAnnouncer} from '../core';
Expand Down Expand Up @@ -236,6 +244,21 @@ describe('MdSnackBar', () => {
});
});
}));

it('should remove snackbar if another is shown while its still animating open', fakeAsync(() => {
snackBar.open('First snackbar');
viewContainerFixture.detectChanges();

snackBar.open('Second snackbar');
viewContainerFixture.detectChanges();

// Flush microtasks to make observables run, but don't tick such that any animations would run.
flushMicrotasks();
expect(overlayContainerElement.textContent.trim()).toBe('Second snackbar');

// Let remaining animations run.
tick(500);
}));
});

@Directive({selector: 'dir-with-view-container'})
Expand Down
3 changes: 1 addition & 2 deletions src/lib/snack-bar/snack-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class MdSnackBar {
/** A reference to the current snack bar in the view. */
private _snackBarRef: MdSnackBarRef<any>;

constructor(private _overlay: Overlay,
private _live: MdLiveAnnouncer) {}
constructor(private _overlay: Overlay, private _live: MdLiveAnnouncer) {}

/**
* Creates and dispatches a snack bar with a custom component for the content, removing any
Expand Down

0 comments on commit 523a48e

Please sign in to comment.