Skip to content

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

Closed

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

Activity

  1. jelbourn commented on Aug 4, 2017

    @jelbourn
    Contributor

    Overall sounds good, we should do both of those things.

    In making _openDialogs public, I'd want to add an id property to the the MdDialogConfig and MdDialogRef (use the config ID on open if it exists, otherwise generate one). Maybe also a getDialogById method. This will make it easier to get at specific dialog instances.

  2. added
    feature
    on Aug 4, 2017
  3. self-assigned this
    on Aug 5, 2017
  4. added 3 commits that reference this issue on Aug 5, 2017
    18ea5bd
    d7530d1
    f911655
  5. added a commit that references this issue on Aug 7, 2017
    c4f29a3
  6. added a commit that references this issue on Aug 7, 2017
    8b54715
  7. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  8. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions