Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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