Skip to content
Overlays Core Stable

Dialog

.md

A modal panel with a title, description, body and free-form footer — portals out, traps focus, and locks the page's scroll while open

Available for Svelte 5, React, and Vue 3.

Preview

Installation

pnpm add fancy-ui-svelte
import { Dialog } from "fancy-ui-svelte";

Usage

svelte
<script lang="ts">
	import { Dialog } from "fancy-ui-svelte";
	import { Button } from "fancy-ui-svelte";

	let open = $state(false);
	let email = $state("");
</script>

{#snippet trigger()}
	<Button>Invite member</Button>
{/snippet}

{#snippet footer()}
	<Button variant="outline" onclick={() => (open = false)}>Cancel</Button>
	<Button onclick={() => (open = false)}>Invite</Button>
{/snippet}

<Dialog
	sound
	bind:open
	{trigger}
	{footer}
	title="Invite a member"
	description="Send an email invite to join the workspace."
>
	<input
		type="email"
		bind:value={email}
		placeholder="email@example.com"
		aria-label="Email address"
		class="border-input bg-background text-muted-foreground placeholder:text-muted-foreground focus-visible:ring-ring/50 focus-visible:border-ring w-full rounded-lg border px-3 py-2 text-[12px] outline-none focus-visible:ring-2"
	/>
</Dialog>

Examples

Basic Usage

A trigger, title, description, body and footer.

Controlled Open

Non-bound open plus onOpenChange, no trigger snippet.

Not Dismissible

dismissible={false} — Escape and outside click both disabled.

Custom Initial Focus

Sends focus to a specific field instead of the default close button.

With Popover

A popover opened inside the dialog — Escape closes one layer at a time.

Interactive Playground

Props

PropTypeDefaultDescription
open booleanfalseWhether the dialog is open; bindable
onOpenChange (open: boolean) => void-Fires whenever open changes, from any trigger
title string-The heading. Omitted entirely (not just visually) when not given
description string-The copy under the title. Same omission rule as title
dismissible booleantrueWhether Escape and an outside click close the dialog; the close button always works
initialFocus HTMLElement | null-Element to focus once the dialog opens; defaults to the first focusable descendant
class string-Additional CSS classes for the panel
ref HTMLDivElement | nullnullBindable reference to the panel element
sound booleanfalsePlays open when the trigger opens the dialog and close on every dismissal, once the user has enabled sound

Slots

SlotDescription
children The dialog's body
footer The action row under the body — free-form, callers build their own buttons
trigger Optional trigger; renders in place and opens the dialog on activation