Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
willshowell opened this issue Aug 4, 2017 · 2 comments · Fixed by #6289
Closed

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

willshowell opened this issue Aug 4, 2017 · 2 comments · Fixed by #6289
Assignees
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix

Comments

@willshowell
Copy link
Contributor

willshowell commented Aug 4, 2017

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
@jelbourn
Copy link
Member

jelbourn commented Aug 4, 2017

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.

@jelbourn jelbourn added the feature This issue represents a new feature or feature request rather than a bug or bug fix label Aug 4, 2017
@crisbeto crisbeto self-assigned this Aug 5, 2017
@crisbeto crisbeto added the has pr label Aug 5, 2017
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 5, 2017
* Makes the `openDialog` public.
* Adds a unique id to each `MdDialogRef`, as well as the option to override the id and to look dialogs by id.
* The `afterAllClosed` stream now emits on subscribe if there are no open dialogs.

Fixes angular#6272.
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 5, 2017
* Makes the `openDialog` public.
* Adds a unique id to each `MdDialogRef`, as well as the option to override the id and to look dialogs by id.
* The `afterAllClosed` stream now emits on subscribe if there are no open dialogs.

Fixes angular#6272.
crisbeto added a commit to crisbeto/material2 that referenced this issue Aug 5, 2017
* Makes the `openDialog` public.
* Adds a unique id to each `MdDialogRef`, as well as the option to override the id and to look dialogs by id.
* The `afterAllClosed` stream now emits on subscribe if there are no open dialogs.

Fixes angular#6272.
mmalerba pushed a commit that referenced this issue Aug 7, 2017
* Makes the `openDialog` public.
* Adds a unique id to each `MdDialogRef`, as well as the option to override the id and to look dialogs by id.
* The `afterAllClosed` stream now emits on subscribe if there are no open dialogs.

Fixes #6272.
mmalerba pushed a commit that referenced this issue Aug 7, 2017
* Makes the `openDialog` public.
* Adds a unique id to each `MdDialogRef`, as well as the option to override the id and to look dialogs by id.
* The `afterAllClosed` stream now emits on subscribe if there are no open dialogs.

Fixes #6272.
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature This issue represents a new feature or feature request rather than a bug or bug fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants