Skip to content

[dialog] improved api for knowing state of all dialogs #6272

Closed
@willshowell

Description

@willshowell

Bug, feature request, or proposal:

Feature request

Motivation

I have a "top priority" dialog that should dismiss all other dialogs before opening. In order to know when no other dialogs are open, I have to access a docs-private property, _openDialogs:

openImportantDialog() {
  // Start closing each of the open dialogs
  this.dialog.closeAll();

  // When all dialogs are closed, open the important dialog
  this.noDialogsOpen.first().subscribe(() => {
    this.dialog.open(MyImportantDialog);
  });
}

/** Emits when no dialogs are open */
get noDialogsOpen(): Observable<void> {
  if (this.dialog._openDialogs.length) {
    return this.dialog.afterAllClosed;
  } else {
    return this.dialog.afterAllClosed.startWith(null);
  }
}

It would be nice if I could do something like

openImportantDialog() {
  this.dialog.afterAllClosed.first().subscribe(() => {
    this.dialog.open(MyImportantDialog);
  });
}

except afterAllClosed only emits after the final dialog closes, but not when there are no dialogs to begin with.

Suggested behavior

One or both of the following:

  1. _openDialogs becomes openDialogs
  2. afterAllClosed (or a new property) emits immediately to new subscribers if no dialogs are currently opened

Metadata

Metadata

Assignees

Labels

featureThis issue represents a new feature or feature request rather than a bug or bug fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions