Modals are opened using a “last in first out” stack. If multiple modals are opened,
the top modal receives an isActive prop of true and the rest receive false. Use this
in your modal component to conditionally render or display the modal.
When a modal is closed it is unmounted and removed from the stack.
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.
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.
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.
Snippets
Snippets can be passed in as props the same way you would with a regular Svelte 5 component.
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.