Modals are opened using a “last in first out” stack. If multiple modals are opened,
only the top one is shown and the others will be hidden (by providing an isActive prop to the modal).
When a modal is closed, it unmounts and shows the next modal in the stack (if there is one).
Opening Modals
Modals are opened with modals.open(YourModalComponent, props).
Multiple Modals
If another modal is opened while a modal is already open, the current modal
will be hidden (by receiving an isActive prop of false) and the new modal will be shown.
Closing Modals
From anywhere in your app you can call modals.close() to close the top modal, modals.close(amount) to
close a given number of modals, or modals.closeAll() to close all modals.
The close() Prop
Modals receive a close prop which will close the modal and resolve
the corresponding modals.open with the given value.
If you are using Typescript, you can define the type of the value by using the ModalProps interface.
Props
Modal components receive the following props:
If you’re using Typescript, you should use this interface to define the props of your modal components.
Transitions
Transitions can be added to your modal components just like any other Svelte component. They
must be global transitions because they are mounted and unmounted by the <ModalStack /> component.
Transitions between Modals
By default, when opening one modal after another the transitions for both will play at the same time.
Depending on your animation this might be ok, but often it’s cleaner to transition one at a time.
To control this behaviour, you can forward on the onintrostart and onoutroend props to your modal.
This tells <ModalStack /> to wait for the transition to finish before opening the next modal.
See how they compare
Lazy Loading
Modal components can be lazy loaded with dynamic imports
While the component is being imported, the <ModalStack /> component will render backdrop and loading snippets.