Skip to content

Commit

Permalink
fix(dialog): prevent dialog from opening while another dialog is anim…
Browse files Browse the repository at this point in the history
…ating

Prevents dialogs from being opened while other dialogs are animating.

Fixes #5713.
  • Loading branch information
crisbeto authored and andrewseguin committed Jul 25, 2017
1 parent 374aaff commit 9ab5519
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/lib/dialog/dialog-container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
'[attr.aria-labelledby]': '_ariaLabelledBy',
'[attr.aria-describedby]': '_config?.ariaDescribedBy || null',
'[@slideDialog]': '_state',
'(@slideDialog.start)': 'this._isAnimating = true',
'(@slideDialog.done)': '_onAnimationDone($event)',
},
})
Expand Down Expand Up @@ -96,6 +97,9 @@ export class MdDialogContainer extends BasePortalHost {
/** ID of the element that should be considered as the dialog's label. */
_ariaLabelledBy: string | null = null;

/** Whether the container is currently mid-animation. */
_isAnimating = false;

constructor(
private _ngZone: NgZone,
private _elementRef: ElementRef,
Expand Down Expand Up @@ -175,5 +179,7 @@ export class MdDialogContainer extends BasePortalHost {
this._restoreFocus();
this._onAnimationStateChange.complete();
}

this._isAnimating = false;
}
}
5 changes: 5 additions & 0 deletions src/lib/dialog/dialog-ref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ export class MdDialogRef<T> {
return this;
}

/** Returns whether the dialog is animating. */
_isAnimating(): boolean {
return this._containerInstance._isAnimating;
}

/** Fetches the position strategy object from the overlay ref. */
private _getPositionStrategy(): GlobalPositionStrategy {
return this._overlayRef.getState().positionStrategy as GlobalPositionStrategy;
Expand Down
14 changes: 11 additions & 3 deletions src/lib/dialog/dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,19 @@ export class MdDialog {
*/
open<T>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
config?: MdDialogConfig): MdDialogRef<T> {

const inProgressDialog = this._openDialogs.find(dialog => dialog._isAnimating());

// If there's a dialog that is in the process of being opened, return it instead.
if (inProgressDialog) {
return inProgressDialog;
}

config = _applyConfigDefaults(config);

let overlayRef = this._createOverlay(config);
let dialogContainer = this._attachDialogContainer(overlayRef, config);
let dialogRef =
const overlayRef = this._createOverlay(config);
const dialogContainer = this._attachDialogContainer(overlayRef, config);
const dialogRef =
this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config);

if (!this._openDialogs.length) {
Expand Down

0 comments on commit 9ab5519

Please sign in to comment.