Skip to content

How to close a modal from a different component? #113

Answered by vnphanquang
multiplehats asked this question in Q&A
Discussion options

You must be logged in to vote

@multiplehats hello there, good question. When calling pop(undefined), the topmost modal on the stack will close. If you know that the modal you're trying to pop is always on top, then all is good.

To close a specific modal in the middle of the stack, you need to pass id of the pushed modal:

modalStore.pop({ id: 'some-thing' } as ModalPushOutput<WebsiteModal>);

This id is returned in the ModalPushOutput:

const { id } = modalStore.push(SomeComponent) // id here is generated for you;
// or
const { id } = modalStore.push({ id: 'user-defined-id', component: SomeComponent }); // id here is same as specified

So you basically have to keep this id somewhere after push (svelte context, another sto…

Replies: 1 comment 15 replies

Comment options

You must be logged in to vote
15 replies
@vnphanquang
Comment options

@multiplehats
Comment options

@vnphanquang
Comment options

@multiplehats
Comment options

@vnphanquang
Comment options

Answer selected by multiplehats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
scope:modal @svelte-put/modal
2 participants