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

bug: IonModal focus trap does not allow other components to overlay #29056

Closed
3 tasks done
hatsantos opened this issue Feb 14, 2024 · 2 comments
Closed
3 tasks done

bug: IonModal focus trap does not allow other components to overlay #29056

hatsantos opened this issue Feb 14, 2024 · 2 comments
Assignees
Labels

Comments

@hatsantos
Copy link

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

When using other components that utilize the Angular CDK or similar methods to present content in an overlay (for example, a select, date, or color picker) within an Ionic modal, this overlay is affected by the Ionic modal's focus. This seems to be related to the class: "ion-disable-focus-trap".

Is there a way to disable this requirement when starting an Ionic modal via a declarative element or via ModalController?

I found a post on Ionic Forum: https://forum.ionicframework.com/t/work-around-for-ionic-modal-focus-trapping/216633/6 where a user described a similar issue and other user sugested a hack:

Copy code
<ion-modal #myModal>
  <ng-template>
    <ion-content>
      <mbsc-datepicker
                    (onOpen)="myModal.cssClass = 'ion-disable-focus-trap'"
                     (onClose)="myModal.cssClass = ''">
       </mbsc-datepicker>
    </ion-content>
  </ng-template>
</ion-modal>

This helps, but not gracefully, as this code has to be duplicated in all Ionic modals where there are other components that utilize the Angular CDK overlays or similar.

Using ModalController and passing a function to the component, something similar to this would be necessary:

onOpen(open: any) {
       this.ModalController.getTop().then(modal => modal?.classList.toggle('ion-disable-focus-trap', open));
}

Expected Behavior

Let user define the modal focus behavior or disable focus trap it not currently necessary ionic framework.

Steps to Reproduce

  1. clone the testing repo
  2. npm install
  3. ionic serve
  4. open the modal
  5. try to interact with the select components

example-issue

Code Reproduction URL

https://hatsbytes@bitbucket.org/hatslab/taigaui-combobox-ionmodal.git

Ionic Info

Ionic:
Ionic CLI : 7.1.5
Ionic Framework : @ionic/angular 7.7.2
@angular-devkit/build-angular : 17.1.3
@angular-devkit/schematics : 17.1.3
@angular/cli : 17.1.3
@ionic/angular-toolkit : 9.0.0

Capacitor:
Capacitor CLI : 5.5.1
@capacitor/android : not installed
@capacitor/core : not installed
@capacitor/ios : not installed

Utility:
cordova-res : not installed globally
native-run : 1.7.4

System:
NodeJS : v20.10.0 (C:\Program Files\nodejs\node.exe)
npm : 10.2.3
OS : Windows 10

Additional Information

No response

@mapsandapps
Copy link
Contributor

Thank you for submitting this issue. I'm going to close this, as it sounds like this is a duplicate of #24646

Copy link

ionitron-bot bot commented Mar 15, 2024

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 Mar 15, 2024
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