Add a beforeClose method for MdDialog
See original GitHub issueFeature Request
What is the expected behavior?
When the user is about to close a MdDialog window (via Esc key, clickout or close button), for example an edit dialog, it would be nice to be able to have some method to prevent the window from closing to avoid unsaved changes for example.
What is the use-case or motivation for changing an existing behavior?
Since the MdDialog already listens to Esc key events, clickout and has the close() method that is used in the action buttons, it would be much easier to have a method like afterClosed that is called just before the closing event is going to occur, so we could prevent it from happening just returning true
or false
in a callback function. This way we don’t have to overwrite those event listeners.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top GitHub Comments
In my opinion
beforeClose
anddisableClose
serve two different purposes. Imagine a scenario where you want to prompt a user before discarding the changes (no matter how the cancellation happened); then usingbeforeClose
would allow us to cancel closing the dialog. However,disableClose
would completely remove the ability for the user to close the dialog (via cancellation) which is not what is expected.Much needed! We have a use-case where we want to save data if the user cancels the dialog (via clicking on backdrop or hitting the Esc key). Where the problem comes in, is if there’s a server error, we want to keep the modal up still to display the message.