dssoca docs
GitHub repository

Modal

Accessible overlay dialog built on native <dialog>.

A modal dialog built on the native `<dialog>` element, so the platform supplies the focus trap, Esc-to-close and an inert backdrop. Bind `open` to your state; the dialog opens/closes in lock-step. Optional `header`/`footer` snippets frame the body, `closeOnBackdrop`/`closeOnEsc` tune dismissal, and `danger` flags destructive dialogs. Sets `aria-labelledby` to the `title` automatically, or accepts an `aria-label` when untitled.

Demo

live · storybook Open in Storybook

Demo loads from https://dssoca-storybook.vercel.app/. Run pnpm storybook for it to render locally.

Usage

svelte
<script>
  import { Modal, Button } from 'dssoca';
  let open = $state(false);
</script>

<Button onclick={() => (open = true)}>Open</Button>
<Modal bind:open title="Confirm action">
  {#snippet footer()}
    <Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
    <Button onclick={() => (open = false)}>Confirm</Button>
  {/snippet}
  <p>Are you sure you want to continue?</p>
</Modal>

Uses the native `<dialog>` element: the browser provides the focus trap, Esc handling and an inert `::backdrop`. `aria-labelledby` points at the title when set; otherwise pass `aria-label`. The close button carries `aria-label="Close"`. Size controls the dialog max-width only. Zero border-radius.

Props

PropTypeDefaultDescription
openbooleanfalseBindable. Whether the modal is shown; syncs to the native dialog.
titlestringHeader title; wires `aria-labelledby`. Omit and pass `aria-label` for an untitled dialog.
closeOnBackdropbooleantrueClicking outside the panel (on the backdrop) closes the modal.
closeOnEscbooleantrueEsc closes the modal. When false the cancel event is prevented.
dangerbooleanfalseStyling hint for destructive dialogs (tints the title).
aria-labelstringAccessible name used when no `title` is set.
onclose() => voidCalled after the dialog closes (Esc, backdrop, or button).
headerSnippetReplaces the default title row in the header.
footerSnippetFooter content, typically a trailing cancel→confirm action pair (the affirmative `Button` trails the dismissive `ghost` one, per dialog convention).
childrenSnippetRequired. The modal body content.
size'sm' | 'md' | 'lg'Per-instance size override; inherits the ancestor `data-size-variant` when unset.