Overview
Reference usage
Mount ModalRegion once in a context boundary and call useModal().openModal or useModal().confirm from descendants. State is scoped to the region and safe during SSR.
Usage
The region owns a scoped registry of open modals, not a serializing queue, and is safe to mount during SSR; useModal() must run inside the region's subtree. Calling openModal or confirm again with a distinct (or auto-generated) id before an earlier one settles renders both concurrently—the second does not wait for the first—so coordinate at the call site if only one modal should be visible at a time. Reusing a still-pending entry's own id does not render a second modal, though: openModal returns the same promise back, and confirm either returns the existing confirmation's promise or, if the id instead collides with a pending ordinary modal, resolves false immediately with nothing rendered. openModal returns a promise that settles when the modal resolves, while confirm provides the binary decision preset. Mount one region at the application boundary that owns this registry. When the region is destroyed, pending ordinary modals resolve to undefined and confirmations resolve to false; handle those dismissal results before applying a change.
When to use
- Application code must open deduplicated modals or await a confirmation result imperatively.
- A single declarative modal is sufficient; use Modal directly.
Examples
Basic modal region
Mount application content inside the modal coordination region.
Props
Name | Type | Default | Description |
|---|---|---|---|
children | import('svelte').Snippet | Descendant application surface that opens modals through useModal(). |