Skip to content

bug: focus trap prevents focus from moving to overlays that do not use focus trapping #24646

Closed
YoutacRandS-VA/eth2-beaconchain-explorer-app
#2

Description

@soroush-gh

Prerequisites

Ionic Framework Version

  • v4.x
  • v5.x
  • v6.x

Current Behavior

I can not focus on search bar input for the "ngx-mat-select-search" or all inputs that they are using to add features such as add link in the MCE Editor when I am using them (mat-select / MCE-Editor) in the ionic-modal.

I thought it was for z-index conflicting and try different ways to solve it but I could not!

image

Expected Behavior

The end-user should be type anything in the inputs that I explained on the top.

Steps to Reproduce

.

Code Reproduction URL

No response

Ionic Info

No response

Additional Information

No response

Activity

  1. JeramieHallyburton commented on Jan 25, 2022

    @JeramieHallyburton

    I have created a simple reproduction of this issue. It appears if an ion-segment exists in the modal, any nested modal inputs cannot grab focus.

    Stackblitz of ion-modal with an ion-segment present and tinyMCE editor
    https://stackblitz.com/edit/modal-with-segment?file=src/app/app.component.html

    1. Click Insert > Link
    2. Observe the text inputs cannot gain focus

    Stackblitz of ion-modal without an ion-segment present and tinyMCE editor
    https://stackblitz.com/edit/modal-without-segment?file=src/app/app.component.html

    1. Click Insert > Link
    2. Observe you can focus and type into text inputs
  2. self-assigned this
    on Jan 25, 2022
  3. added
    package: core
    type: bug
    on Feb 11, 2022
  4. removed their assignment
    on Feb 11, 2022
  5. kalozoya-orisha commented on Mar 22, 2022

    @kalozoya-orisha

    I have the same problem with ngx-mat-select-search inside modal.

    I have made an example where outside modal the input search of select works, but inside modal without an ion-segment i can't search select values.

    https://stackblitz.com/edit/modal-without-segment-rhkczi?file=src/app/app.component.html

  6. liamdebeasi commented on May 18, 2022

    @liamdebeasi
    Contributor

    This appears to be an issue with focus trapping. When you present ion-modal, we prevent focus from leaving the modal for better accessibility. However, the tinyMCE editor is presented at the root of the app outside of the ion-modal. As a result, when you try to focus an input in the editor, ion-modal brings focus back to the first focusable element. In this case, that is the segment button.

  7. changed the title [-]bug: Can not focus on the text inputs the modal and type something[/-] [+]bug: focus trap interferes with non-Ionic overlays presented from modal or popover[/+] on Jul 8, 2022
  8. inexuscore commented on May 7, 2023

    @inexuscore

    This appears to be an issue with focus trapping. When you present ion-modal, we prevent focus from leaving the modal for better accessibility. However, the tinyMCE editor is presented at the root of the app outside of the ion-modal. As a result, when you try to focus an input in the editor, ion-modal brings focus back to the first focusable element. In this case, that is the segment button.

    Is there a workaround to this issue? I'm using TinyMCE in an Ionic 7 project, the plugin dialogs (e.g. the TinyMCE Link Plugin) work fine on ionic pages, but not when I use an editor inside an ion-modal. Focus trapping! None of the input elements are focusable. Any ideas how I can get around this?

  9. soroush-gh commented on May 8, 2023

    @soroush-gh
    Author

    This appears to be an issue with focus trapping. When you present ion-modal, we prevent focus from leaving the modal for better accessibility. However, the tinyMCE editor is presented at the root of the app outside of the ion-modal. As a result, when you try to focus an input in the editor, ion-modal brings focus back to the first focusable element. In this case, that is the segment button.

    Is there a workaround to this issue? I'm using TinyMCE in an Ionic 7 project, the plugin dialogs (e.g. the TinyMCE Link Plugin) work fine on ionic pages, but not when I use an editor inside an ion-modal. Focus trapping! None of the input elements are focusable. Any ideas how I can get around this?

    Use this CSS class ion-disable-focus-trap on creating ion-modal
    image

  10. changed the title [-]bug: focus trap interferes with non-Ionic overlays presented from modal or popover[/-] [+]bug: focus trap prevents focus from moving to overlays that do not use focus trapping[/+] on Sep 29, 2023
  11. added
    type: bug
    and removed
    type: bug
    on Sep 29, 2023
  12. hatsantos commented on Feb 15, 2024

    @hatsantos

    Regarding the recent closed issue #29056, is there a recomended way to avoid the focus trap on modal?

  13. GerardoTovar commented on Feb 18, 2024

    @GerardoTovar

    Thanks in my case, adding it using cssClass did not work for me, but adding it using an id before opening the modal worked perfectly for me.
    similar to the recent closed issue #29056
    <ion-modal id="ionModals"
    addClass() { document.getElementById('ionModals')?.classList.add('ion-disable-focus-trap') }

  14. hatsantos commented on Feb 26, 2024

    @hatsantos

    Would it make sense in the ModalController object's configuration API to have a boolean to activate or not the focus trap?

    Something like:

    const modal = await this.modalCtrl.create({
          component: ModalExampleComponent,
          focusTrap: false // (default true)
    });
    
  15. liamdebeasi commented on Apr 11, 2024

    @liamdebeasi
    Contributor

    Hi everyone,

    I have a dev build with a proposed feature to resolve this if anyone is interested in testing: 8.0.0-dev.11712850753.10c4a960

    Note that this is an Ionic 8 dev build and is subject to the Ionic 8 breaking changes list.

    To disable focus trapping, set the focusTrap property on either Modal or Popover to false. (Defaults to true)

  16. hatsantos commented on Apr 11, 2024

    @hatsantos

    Hi @liamdebeasi I will try to test it latter on.

    My project in currently on version 7 so i will have to check what needs to be done to upgrade to version 8.

  17. kalozoya-orisha commented on Apr 12, 2024

    @kalozoya-orisha
  18. hatsantos commented on Apr 13, 2024

    @hatsantos

    I only had the opportunity to test it now.
    I changed it from this:

    image

    To this:

    image

    No problems at all. ;)

    But taking as an example by just disabling the focus trap when activating a certain component (dropdown) within the modal.
    Previously, I used this technique:

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

    Would there be any way to modify the focusTrap prop in this context?

  19. liamdebeasi commented on Apr 15, 2024

    @liamdebeasi
    Contributor

    Would there be any way to modify the focusTrap prop in this context?

    In this case you could do something like modal.focusTrap = true to re-enable the focus trapping behavior. model is a reference to the ion-modal element.

    Alternatively, you could pass a prop to the modal component that toggles focusTrap when invoked.

  20. added a commit that references this issue on Apr 25, 2024
    7c00351
  21. liamdebeasi commented on Apr 25, 2024

    @liamdebeasi
    Contributor

    Thanks for the issue. This has been resolved via #29379, and a fix will be available in an upcoming release of Ionic Framework.

  22. ionitron-bot commented on May 25, 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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    package: coretype: bug

    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