ionic-team / ionic-framework

A powerful cross-platform UI toolkit for building native-quality iOS, Android, and Progressive Web Apps with HTML, CSS, and JavaScript.
https://ionicframework.com
MIT License
51.03k stars 13.51k forks source link

feat: Create method to close all active dialogs and/or alerts #24630

Closed ndrakulic91 closed 2 years ago

ndrakulic91 commented 2 years ago

Prerequisites

Describe the Feature Request

Currently ModalController and AlertController are able to dismiss one modal at the time. In case of stacked modals/alerts, closing all active ones is not possible unless we keep track of those that are shown.

It would be very helpful if there would be a dismissAll() method which would close all active modals for ModalController or alerts for AlertController.

Describe the Use Case

A practical example is when user gets automatically logged out, all activr overlays should be closed. In case of stacked overlays it's impossible unless those are closed one by one using dismiss() method.

Describe Preferred Solution

No response

Describe Alternatives

No response

Related Code

No response

Additional Information

No response

FranciskoNeves commented 2 years ago

I have the same problem, and I think that every Controller should have one "dissmissAll" function, and should exist one to close all Overlays at once like "dismissAllOverlays"

averyjohnston commented 2 years ago

Thanks for the issue. Overlays can also be dismissed by calling dismiss() on the element itself. Could you try the below snippet and let me know if it solves your use case?

import { HTMLIonOverlayElement } from '@ionic/core';

const closeAll = () => {
  // adjust selector to fit your needs
  const overlays = document.querySelectorAll('ion-alert, ion-action-sheet, ion-loading, ion-modal, ion-picker, ion-popover, ion-toast');
  const overlaysArr = Array.from(overlays) as HTMLIonOverlayElement[];
  overlaysArr.forEach(o => o.dismiss());
};
ionitron-bot[bot] commented 2 years ago

Thanks for the issue! This issue is being closed due to the lack of a reply. 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.

Thank you for using Ionic!