components icon indicating copy to clipboard operation
components copied to clipboard

Dialog close / Dialog cancel

Open mbeckenbach opened this issue 9 years ago • 4 comments

Bug, feature request, or proposal:

Feature request

What is the expected behavior?

There should be two methods for closing a dialog. One for a close and one for a cancel.

What is the current behavior?

There is only one close method and so only one afterClosed.

What are the steps to reproduce?

Create any dialog

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

Imagine an edit dialog with a save and a cancel button. At the moment you would have to pass something intro the close method and check for it after close to detect a save action. Would be much easier if there where two different events to subscribe. afterClose and afterCancel.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

ng 4.1.x, md beta 5

Is there anything else we should know?

mbeckenbach avatar May 16 '17 07:05 mbeckenbach

Doing this would be tying the content of the dialog to the dialog semantics. The dialog itself only cares whether it is opened or closed; the fact that one "close" means one thing and that another "close" means another is a user-space concern.

jelbourn avatar May 16 '17 16:05 jelbourn

Thanks for the response, @jelbourn , do you have a 'best practice' for how to approach this problem? I find that in all the cases that I have a dialog, I end up calling this.dialog.close(true) or this.dialog.close(false) and then have an if statement in the afterClosed callback eg

afterClosed().subscribe(success => {
    if (success) {
        // perform action
    }
}

This feels a lot less elegant than the $mdDialog.hide() and $mdDialog.cancel() methods in material 1.x

gseabrook avatar May 17 '17 02:05 gseabrook

@gseabrook you could ignore the undefined/falsey close values:

this.dialog.open(MyDialogComponent, config)
  .afterClosed()
  .filter(x => !!x)
  .subscribe(val => this.successAction(val))

willshowell avatar May 17 '17 21:05 willshowell

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.