Skip to content

Commit 36f708c

Browse files
crisbetoandrewseguin
authored andcommitted
fix(dialog): prevent dialog from opening while another dialog is animating (#5769)
Prevents dialogs from being opened while other dialogs are animating. Fixes #5713.
1 parent b105039 commit 36f708c

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/lib/dialog/dialog-container.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export function throwMdDialogContentAlreadyAttachedError() {
6868
'[attr.aria-labelledby]': '_ariaLabelledBy',
6969
'[attr.aria-describedby]': '_config?.ariaDescribedBy || null',
7070
'[@slideDialog]': '_state',
71+
'(@slideDialog.start)': 'this._isAnimating = true',
7172
'(@slideDialog.done)': '_onAnimationDone($event)',
7273
},
7374
})
@@ -96,6 +97,9 @@ export class MdDialogContainer extends BasePortalHost {
9697
/** ID of the element that should be considered as the dialog's label. */
9798
_ariaLabelledBy: string | null = null;
9899

100+
/** Whether the container is currently mid-animation. */
101+
_isAnimating = false;
102+
99103
constructor(
100104
private _ngZone: NgZone,
101105
private _elementRef: ElementRef,
@@ -175,5 +179,7 @@ export class MdDialogContainer extends BasePortalHost {
175179
this._restoreFocus();
176180
this._onAnimationStateChange.complete();
177181
}
182+
183+
this._isAnimating = false;
178184
}
179185
}

src/lib/dialog/dialog-ref.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ export class MdDialogRef<T> {
9797
return this;
9898
}
9999

100+
/** Returns whether the dialog is animating. */
101+
_isAnimating(): boolean {
102+
return this._containerInstance._isAnimating;
103+
}
104+
100105
/** Fetches the position strategy object from the overlay ref. */
101106
private _getPositionStrategy(): GlobalPositionStrategy {
102107
return this._overlayRef.getState().positionStrategy as GlobalPositionStrategy;

src/lib/dialog/dialog.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,19 @@ export class MdDialog {
115115
*/
116116
open<T>(componentOrTemplateRef: ComponentType<T> | TemplateRef<T>,
117117
config?: MdDialogConfig): MdDialogRef<T> {
118+
119+
const inProgressDialog = this._openDialogs.find(dialog => dialog._isAnimating());
120+
121+
// If there's a dialog that is in the process of being opened, return it instead.
122+
if (inProgressDialog) {
123+
return inProgressDialog;
124+
}
125+
118126
config = _applyConfigDefaults(config);
119127

120-
let overlayRef = this._createOverlay(config);
121-
let dialogContainer = this._attachDialogContainer(overlayRef, config);
122-
let dialogRef =
128+
const overlayRef = this._createOverlay(config);
129+
const dialogContainer = this._attachDialogContainer(overlayRef, config);
130+
const dialogRef =
123131
this._attachDialogContent(componentOrTemplateRef, dialogContainer, overlayRef, config);
124132

125133
if (!this._openDialogs.length) {

0 commit comments

Comments
 (0)