Skip to content

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

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

Closed
3 tasks done
bbonczek opened this issue Jul 6, 2023 · 5 comments
Closed
3 tasks done

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

bbonczek opened this issue Jul 6, 2023 · 5 comments
Labels

Comments

@bbonczek
Copy link

bbonczek commented Jul 6, 2023

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

@ionitron-bot ionitron-bot bot added the triage label Jul 6, 2023
@liamdebeasi liamdebeasi self-assigned this Jul 6, 2023
@liamdebeasi
Copy link
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.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Jul 6, 2023
@liamdebeasi liamdebeasi removed their assignment Jul 6, 2023
@ionitron-bot ionitron-bot bot removed the triage label Jul 6, 2023
@bbonczek
Copy link
Author

bbonczek commented Jul 7, 2023

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.

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jul 7, 2023
@liamdebeasi
Copy link
Contributor

liamdebeasi commented Jul 7, 2023

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.

@liamdebeasi liamdebeasi added the needs: reply the issue needs a response from the user label Jul 7, 2023
@ionitron-bot ionitron-bot bot removed the triage label Jul 7, 2023
liamdebeasi added a commit to ionic-team/ionic-docs that referenced this issue Jul 7, 2023
There was some confusion around swipe gestures + modals on ionic-team/ionic-framework#27753. Developer thought the swipe gesture applied to all modals, but it only applies to card and sheet modals.
@bbonczek
Copy link
Author

Thanks!

@ionitron-bot ionitron-bot bot added triage and removed needs: reply the issue needs a response from the user labels Jul 10, 2023
@ionitron-bot
Copy link

ionitron-bot bot commented Aug 9, 2023

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 Aug 9, 2023
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