svelte-modals icon indicating copy to clipboard operation
svelte-modals copied to clipboard

Add `option.onClose` for `openModal` fn.

Open michaltaberski opened this issue 1 year ago • 1 comments

I think adding a close handler to openModal fn could make the componet very flexible.

Imagine a scenario like this:

const confirmModal = ({question}) => new Promise(resolve => 
  openModal(ConfirmModal, onConfirm: () => resolve(true), { onClose: () => resolve(false) })
);

const isConfirmed = await confirmModal({question: "Are you sure?"});

OFC I can add an event handler to Cancel button or corner X button, but what about closing stuff programmatically from another place (eg. by clicking backdrop)?

michaltaberski avatar Feb 25 '23 15:02 michaltaberski