Skip to content

bug: canDismiss option doesn't work when used in modal controller #27753

Closed

Description

@bbonczek

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

Using this code:

@Component({
  selector: 'app-example',
  templateUrl: 'example.component.html',
})
export class ExampleComponent {
  constructor(private modalCtrl: ModalController) {}

  async openModal() {
    const modal = await this.modalCtrl.create({
      component: ModalExampleComponent,
      canDismiss: true,
    });
    modal.present();

    const { data, role } = await modal.onWillDismiss();
  }
}

opens a modal that is not dismissable.

Expected Behavior

Modal should be dismissable, as canDismiss option has been set to true.

Steps to Reproduce

  1. Run example in attached URL and click 'Open'.
  2. Try to dismiss modal with gesture.

Code Reproduction URL

https://stackblitz.com/edit/angular-1akhtj-j7fysu?file=src%2Fapp%2Fexample.component.ts

Ionic Info

➜  ionic info

Ionic:

   Ionic CLI                     : 7.1.1 (/Users/redacted/.nvm/versions/node/v18.12.1/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 7.0.9
   @angular-devkit/build-angular : 15.2.8
   @angular-devkit/schematics    : 15.2.8
   @angular/cli                  : 15.2.8
   @ionic/angular-toolkit        : 9.0.0

Capacitor:

   Capacitor CLI      : 5.0.4
   @capacitor/android : 5.0.4
   @capacitor/core    : 5.0.4
   @capacitor/ios     : 5.0.4

Cordova:

   Cordova CLI       : not installed
   Cordova Platforms : not available
   Cordova Plugins   : not available

Utility:

   cordova-res : not installed globally
   native-run  : 1.7.2

System:

   NodeJS : v18.12.1 (/Users/redacted/.nvm/versions/node/v18.12.1/bin/node)
   npm    : 8.19.2
   OS     : macOS Unknown
   Xcode  : Xcode 14.2 Build version 14C18

Additional Information

This feature appears to be working fine, when using inline <ion-modal> element. Only ModalController is affected. Example in the documentation using <ion-modal> approach is fine: https://stackblitz.com/edit/angular-qwjldx?file=src%2Fapp%2Fexample.component.html

Activity

  1. self-assigned this
    on Jul 6, 2023
  2. liamdebeasi commented on Jul 6, 2023

    @liamdebeasi
    Contributor

    Thanks for the report. Ionic seems to be working as intended here. Your modal does not have a gesture, so swiping to dismiss the modal should not do anything. Pressing the "Escape" key does dismiss the modal, which would indicate canDismiss is working correctly.

  3. removed their assignment
    on Jul 6, 2023
  4. bbonczek commented on Jul 7, 2023

    @bbonczek
    Author

    Hi @liamdebeasi, thanks for a response. Could you share what should be done in the example to allow dismissing modal with a gesture? According to the documentation, this should be the default behaviour - it says that you can prevent dismissing modal by gesture by excluding 'gesture' role.

    Developers may want to prevent users from swiping to close a modal. This can be done by setting a callback function for canDismiss and checking if the role is not gesture.

  5. added and removed
    needs: replythe issue needs a response from the user
    on Jul 7, 2023
  6. liamdebeasi commented on Jul 7, 2023

    @liamdebeasi
    Contributor

    The swiping only applies to card or sheet modals, and the demo at that link uses a card modal. I opened ionic-team/ionic-docs#3021 to clarify this on the docs.

  7. bbonczek commented on Jul 10, 2023

    @bbonczek
    Author

    Thanks!

  8. added and removed
    needs: replythe issue needs a response from the user
    on Jul 10, 2023
  9. ionitron-bot commented on Aug 9, 2023

    @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.

  10. locked and limited conversation to collaborators on Aug 9, 2023
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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions