Skip to content

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

Closed as not planned

Description

@hatsantos

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://[email protected]/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

Activity

  1. mapsandapps commented on Feb 14, 2024

    @mapsandapps
    Contributor

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

  2. ionitron-bot commented on Mar 15, 2024

    @ionitron-bot

    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.

  3. locked and limited conversation to collaborators on Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions