# Dialog

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

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Overlays
- Tags: modal, dialog, overlay, portal, focus-trap
- Types: `DialogProps`
- Docs: https://fancy-ui.rama.app/docs/components/dialog
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/dialog

## Import

```tsx
import { Dialog } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | `false` | Whether 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` | `boolean` | `true` | Whether 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 |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes for the panel |
| `ref` | `HTMLDivElement \| null` | `null` | Bindable reference to the panel element |
| `sound` | `boolean` | `false` | Plays open when the trigger opens the dialog and close on every dismissal, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `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 |

## Example

```tsx
import { useState } from "react";
import { Button, Dialog } from "fancy-ui-react";

export function DialogExample() {
	const [open, setOpen] = useState(false);
	const [email, setEmail] = useState("");

	return (
		<Dialog
			open={open}
			onOpenChange={setOpen}
			trigger={<Button>Invite member</Button>}
			footer={
				<>
					<Button variant="outline" onClick={() => setOpen(false)}>
						Cancel
					</Button>
					<Button onClick={() => setOpen(false)}>Invite</Button>
				</>
			}
			title="Invite a member"
			description="Send an email invite to join the workspace."
		>
			<input
				type="email"
				value={email}
				onChange={(event) => setEmail(event.target.value)}
				placeholder="email@example.com"
				aria-label="Email address"
				className="border-input bg-background w-full rounded-lg border px-3 py-2 text-sm"
			/>
		</Dialog>
	);
}
```
