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

[Enhancement] Modal: Alert before close #376

Closed
jakobe opened this issue Jun 26, 2019 · 8 comments · Fixed by #2514
Closed

[Enhancement] Modal: Alert before close #376

jakobe opened this issue Jun 26, 2019 · 8 comments · Fixed by #2514
Assignees

Comments

@jakobe
Copy link
Collaborator

jakobe commented Jun 26, 2019

It should be possible to add an (optional) alert configuration when calling modalController.showModal(config) and opening the modal window.
The alert should be shown when dismissing the modal (clicking the close button or esc key) and depending on the user interaction (true/false) the modal dismisses or not.

Note: If there is no hook for cancelling the dismissal (e.g. onModalWillDismiss => true/false) then we should limit the dismiss to the close button and handle the alert before calling modalController.hideTopMost()

Skærmbillede 2020-10-28 kl  10 10 03

@labanos
Copy link
Contributor

labanos commented Jul 11, 2019

moving to after release 1 for now - might reconsider if it highly needed by more teams than (team2?) - also workarounds might be possible?

@bommariusser
Copy link
Contributor

@labanos @jakobe @hafstad can we talk about this on monday?

@bduphl
Copy link

bduphl commented Mar 27, 2020

I would like to suggest that presentation of the alert depends on a condition. For instance, only show an alert when something is typed in an input field within the component.

@bommariusser
Copy link
Contributor

@hafstad det er ikke lavet endnu eller?

@hafstad hafstad self-assigned this Jun 7, 2021
@alxzak alxzak removed this from the Masterplanning 5 - end of 2020 milestone Jun 21, 2021
@alxzak
Copy link
Collaborator

alxzak commented Aug 19, 2021

This issue will be closed due to backlog prioritization and pruning.
#1704 (comment)

@alxzak alxzak closed this as completed Aug 19, 2021
@LVinther
Copy link

@alxzak can this issue be reopened? We need it in team 3 :)

@henrikvoetmand
Copy link
Collaborator

With the updated modal behavior, where you can drag to close on the entire modal dialog, it is even more important to have this "Alert before close" functionality. (The new modal behavior comes with the Ionic 6 upgrade)

@alxzak alxzak added this to Kirby Sep 8, 2022
@RasmusKjeldgaard RasmusKjeldgaard moved this to 💡 Shaping in Kirby Sep 19, 2022
@mark-drastrup mark-drastrup self-assigned this Sep 27, 2022
@mark-drastrup
Copy link
Contributor

mark-drastrup commented Sep 27, 2022

Ionic 6 provides a way to prevent a modal from being dismissed, by passing in a boolean or a callback that returns a boolean. https://ionicframework.com/docs/api/modal#setting-a-callback-function. We can utilize the canDismiss callback to show an alert, that either prevents or allows the modal to be closed.

Here is a working POC that is based on the example in the Ionic documentation:

modal.helper.ts

const canDismiss = async () => {
  const actionSheet = await this.actionSheetCtrl.create({
    header: 'Are you sure?',
    buttons: [
      {
        text: 'Yes',
        role: 'confirm',
      },
      {
        text: 'No',
        role: 'cancel',
      },
    ],
  });

  actionSheet.present();

  const { role } = await actionSheet.onWillDismiss();

  return role === 'confirm';
};

const ionModal = await this.ionicModalController.create({
  component: config.flavor === 'compact' ? ModalCompactWrapperComponent : ModalWrapperComponent,
  cssClass: [
    'kirby-overlay',
    'kirby-modal',
    config.flavor === 'drawer' ? 'kirby-drawer' : null,
    config.flavor === 'compact' ? 'kirby-modal-compact' : null,
    modalSize ? 'kirby-modal-' + modalSize : null,
    config.interactWithBackground ? 'interact-with-background' : null,
    ...customCssClasses,
  ],
  backdropDismiss: config.flavor === 'compact' || config.interactWithBackground ? false : true,
  showBackdrop: !config.interactWithBackground,
  componentProps: { config: config },
  swipeToClose: config.flavor != 'compact',
  presentingElement: modalPresentingElement,
  keyboardClose: false,
  canDismiss: canDismiss, <-------------
  enterAnimation,
  leaveAnimation,
});

We could follow this approach and make it possible for the developers to pass in an alert config instead of the hardcoded actionsheet.

@mark-drastrup mark-drastrup moved this from 💡 Shaping to 🚀 In Progress in Kirby Sep 28, 2022
@mark-drastrup mark-drastrup moved this from 🚀 In Progress to 🔎 Review pending in Kirby Oct 3, 2022
@mictro mictro moved this from 🔎 Review pending to 👀 Review in progess in Kirby Oct 24, 2022
Repository owner moved this from 👀 Review in progess to ✅ Done in Kirby Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
10 participants