Skip to content

Commit 523a48e

Browse files
authored
fix(snackbar): remove even if still animating open (#1797)
1 parent fcd29c8 commit 523a48e

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

src/lib/snack-bar/snack-bar-container.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ export class MdSnackBarContainer extends BasePortalHost {
9292

9393
/** Mark snack bar as exited from the view. */
9494
markAsExited(event: AnimationTransitionEvent) {
95-
if (event.fromState === 'visible' &&
96-
(event.toState === 'void' || event.toState === 'complete')) {
95+
if (event.toState === 'void' || event.toState === 'complete') {
9796
this._ngZone.run(() => {
9897
this._onExit.next();
9998
this._onExit.complete();

src/lib/snack-bar/snack-bar.spec.ts

+24-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import {inject, async, ComponentFixture, TestBed} from '@angular/core/testing';
1+
import {
2+
inject,
3+
async,
4+
ComponentFixture,
5+
TestBed,
6+
fakeAsync,
7+
flushMicrotasks,
8+
tick,
9+
} from '@angular/core/testing';
210
import {NgModule, Component, Directive, ViewChild, ViewContainerRef} from '@angular/core';
311
import {MdSnackBar, MdSnackBarModule} from './snack-bar';
412
import {OverlayContainer, MdLiveAnnouncer} from '../core';
@@ -236,6 +244,21 @@ describe('MdSnackBar', () => {
236244
});
237245
});
238246
}));
247+
248+
it('should remove snackbar if another is shown while its still animating open', fakeAsync(() => {
249+
snackBar.open('First snackbar');
250+
viewContainerFixture.detectChanges();
251+
252+
snackBar.open('Second snackbar');
253+
viewContainerFixture.detectChanges();
254+
255+
// Flush microtasks to make observables run, but don't tick such that any animations would run.
256+
flushMicrotasks();
257+
expect(overlayContainerElement.textContent.trim()).toBe('Second snackbar');
258+
259+
// Let remaining animations run.
260+
tick(500);
261+
}));
239262
});
240263

241264
@Directive({selector: 'dir-with-view-container'})

src/lib/snack-bar/snack-bar.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ export class MdSnackBar {
3333
/** A reference to the current snack bar in the view. */
3434
private _snackBarRef: MdSnackBarRef<any>;
3535

36-
constructor(private _overlay: Overlay,
37-
private _live: MdLiveAnnouncer) {}
36+
constructor(private _overlay: Overlay, private _live: MdLiveAnnouncer) {}
3837

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

0 commit comments

Comments
 (0)