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

md-dialog Before close functionality? #6369

Closed
vapits opened this issue Aug 9, 2017 · 7 comments
Closed

md-dialog Before close functionality? #6369

vapits opened this issue Aug 9, 2017 · 7 comments

Comments

@vapits
Copy link

vapits commented Aug 9, 2017

Bug, feature request, or proposal:

Feature?

What is the expected behavior?

When user clicks on backdrop or esc the dialog closes. It would be nice to give the user the option to intercept this close method and prevent default behavior based on some condition.

What is the use-case or motivation for changing an existing behavior?

For example if Dialog contains a form, to be able to disable close or display a message (or whatever function he/she wants to run) and prevent the modal from closing.

@willshowell
Copy link
Contributor

Duplicate of #4647.

For your use case specifically, see #4647 (comment) and #3460.

@vapits
Copy link
Author

vapits commented Aug 9, 2017

@willshowell so comment mentioned doesn't match the next issue. Will the PR mentioned be a part of one of the next releases?

@willshowell
Copy link
Contributor

beforeClose (#4647) will eventually be implemented to give users the ability to respond immediately instead of waiting for the animation to complete. However, it won't allow cancelling the close.

So in order to cancel the close (e.g. to show a message when the form needs to be saved or whatever), you would have to pass disableClose to the dialog. Then you would be able to subscribe to backdropClick and escapeKeyEvent streams to show the message or close the dialog on your own.

Those two streams are not yet available and that's what #3460 is all about (particularly the last ~5-6 comments). However, once #6330 is completed, that will be easy work to make them part of the dialog's public api.

In summary, I doubt they'll be in the next release, but probably in the following 1-2.

@jelbourn
Copy link
Member

Duplicate of #4647

@jelbourn jelbourn marked this as a duplicate of #4647 Aug 17, 2017
@dfmmalaw
Copy link

dfmmalaw commented Sep 7, 2017

@willshowell I am new to Angular but I was wondering if you could provide a fiddle showing how you would do the following:

"So in order to cancel the close (e.g. to show a message when the form needs to be saved or whatever), you would have to pass disableClose to the dialog. Then you would be able to subscribe to backdropClick and escapeKeyEvent streams to show the message or close the dialog on your own."

@willshowell
Copy link
Contributor

@dfmmalaw this won't be available until #6682 lands. It could look like this:

const dialogRef = dialog.open(MyDialogComponent, {disableClose: true});

const escapeEvents = dialogRef.keydownEvents().filter(e => e.key === 'Escape');

Observable.merge(escapeEvents, dialogRef.backdropClick())
  .map(() => confirm('Are you sure you want to cancel?'))
  .filter(confirmed => !!confirmed)
  .first()
  .subscribe(() => dialog.close());
  

@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 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants