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

feat: add a property canDismiss to overlays #22626

Closed
188599 opened this issue Dec 4, 2020 · 2 comments
Closed

feat: add a property canDismiss to overlays #22626

188599 opened this issue Dec 4, 2020 · 2 comments
Labels

Comments

@188599
Copy link

188599 commented Dec 4, 2020

Feature Request

Ionic version:

[x] 4.x

Describe the Feature Request

I'd like a way to pass a validation function that should be called before dismissing a modal (or just overlays in general), akin to Angular's CanDeactivate that's implemented on their routes.

Describe Preferred Solution

Ideally, you should be able to pass function that can returns a () => (boolean | Promise<boolean> | Observable<boolean>) during the create method of the overlay, or even after it was already created. When the overlay calls the dismiss method, it should before anything, execute this function and if it resolves to true, proceed with closing it, otherwise maintain it open.

Related Code

const modal = await this.modalCtrl.create({
  ...
  canDismiss: () => true
});

...
    
modal.canDismiss = () => Promise.resolve(false);

Additional Context

Just to explain why I would like to see this.

Some of our forms are used inside modals. Currently we have a problem with them, specifically on Android, because of it's hardware back button the user can simply close the modal by pressing it.

Overriding the the hardware back button is not a very good solution, since it's a modal we have to pass the highest priority to the subscribeWithPriority method, it would override all the calls to it, including those happening when there's another overlay on top of it, and I'm not very sure how we could circumvent that.

@ionitron-bot ionitron-bot bot added the triage label Dec 4, 2020
@liamdebeasi
Copy link
Contributor

Thanks for the issue. I am going to close this as a duplicate of #22297. The issue was originally intended only for the card-style modals, but I think this would be useful to have for any kind of modal in Ionic Framework.

@ionitron-bot
Copy link

ionitron-bot bot commented Jan 3, 2021

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Jan 3, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants