Skip to content

Commit

Permalink
fix(bottom-sheet): error when attempting to open multiple instances q…
Browse files Browse the repository at this point in the history
…uickly (#10147)

Fixes an error that is thrown when attempting to open more than three bottom sheets in quick succession.
  • Loading branch information
crisbeto authored and jelbourn committed Mar 9, 2018
1 parent 9337ae1 commit 34e96f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/lib/bottom-sheet/bottom-sheet-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr
/** Server-side rendering-compatible reference to the global document object. */
private _document: Document;

/** Whether the component has been destroyed. */
private _destroyed: boolean;

constructor(
private _elementRef: ElementRef,
private _changeDetectorRef: ChangeDetectorRef,
Expand Down Expand Up @@ -121,18 +124,23 @@ export class MatBottomSheetContainer extends BasePortalOutlet implements OnDestr

/** Begin animation of bottom sheet entrance into view. */
enter(): void {
this._animationState = 'visible';
this._changeDetectorRef.detectChanges();
if (!this._destroyed) {
this._animationState = 'visible';
this._changeDetectorRef.detectChanges();
}
}

/** Begin animation of the bottom sheet exiting from view. */
exit(): void {
this._animationState = 'hidden';
this._changeDetectorRef.markForCheck();
if (!this._destroyed) {
this._animationState = 'hidden';
this._changeDetectorRef.markForCheck();
}
}

ngOnDestroy() {
this._breakpointSubscription.unsubscribe();
this._destroyed = true;
}

_onAnimationDone(event: AnimationEvent) {
Expand Down
11 changes: 11 additions & 0 deletions src/lib/bottom-sheet/bottom-sheet.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ describe('MatBottomSheet', () => {
expect(overlayContainerElement.textContent).toContain('Taco');
}));

it('should not throw when opening multiple bottom sheet in quick succession', fakeAsync(() => {
expect(() => {
for (let i = 0; i < 3; i++) {
bottomSheet.open(PizzaMsg);
viewContainerFixture.detectChanges();
}

flush();
}).not.toThrow();
}));

it('should remove bottom sheet if another is shown while its still animating open',
fakeAsync(() => {
bottomSheet.open(PizzaMsg);
Expand Down

0 comments on commit 34e96f5

Please sign in to comment.