# Dialog (@limerdev/zest) A modal window over the page: focus moves into it and stays there, Escape and the close button close it, and focus returns to the trigger. `` (`bind:open`) holds a `Dialog.Trigger` (a button: `variant`, `size`) and a `Dialog.Content` with a `Dialog.Header` (`Dialog.Title`, needed, and `Dialog.Description`) and a `Dialog.Footer`. - Category: Overlays - Import: `import { Dialog } from '@limerdev/zest'` - Bits UI: `Dialog`, https://bits-ui.com/docs/components/dialog - Exports: `Dialog.Root`, `Dialog.Trigger`, `Dialog.Close`, `Dialog.Portal`, `Dialog.Overlay`, `Dialog.Content`, `Dialog.Header`, `Dialog.Footer`, `Dialog.Title`, `Dialog.Description` - Use for: Confirming a destructive action, a short form (rename, invite), details that need the user's full attention before they go on. - Don't: Long or multi-step flows: use a page. Information the user can ignore: use a toast or an inline alert. A Dialog.Content without a Dialog.Title. Stacking dialogs. Confirming something that can't be undone: use `AlertDialog`. ```svelte Rename project Rename project The name shows in the sidebar and in emails. Cancel ``` Props of `Dialog.Root`: - `onOpenChange` (`OnChangeFn`): A callback that is called when the popover's open state changes. - `onOpenChangeComplete` (`OnChangeFn`): A callback called when the dialog finishes opening/closing animations. - `open` (`boolean`, default `false`, bindable): The open state of the dialog. Props of `Dialog.Trigger`: - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'primary'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `Dialog.Close`: - `size` (`"default" | "sm" | "lg" | "icon" | "icon-sm" | "icon-lg"`, default `'default'`): The height and padding, from the theme's field size; the `icon` sizes are square. - `variant` (`"link" | "primary" | "secondary" | "neutral" | "error" | "outline" | "ghost"`, default `'primary'`): The look, by the theme's colour roles: `primary` for the main action, `error` for deleting, `secondary`, `neutral` and `outline` for the rest, `ghost` in toolbars, `link` for a navigation that looks like text. Props of `Dialog.Portal`: - `disabled` (`boolean`, default `false`): Disable portalling and render the component inline - `to` (`PortalTarget`, default `document.body`): Where to portal the content to. Props of `Dialog.Overlay`: - `forceMount` (`boolean`): Whether to force mount the component. Props of `Dialog.Content`: - `closeLabel` (`string`, default `the Config's `strings.close`, else 'Close'`): The close button's name for screen readers. - `escapeKeydownBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Escape behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to its parent component that has an escape keydown handler. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an escape key press. - `forceMount` (`boolean`): Whether to force mount the component. - `interactOutsideBehavior` (`"close" | "defer-otherwise-close" | "defer-otherwise-ignore" | "ignore"`, default `close`): Interact outside behavior type. `close`: Closes the element immediately. `defer-otherwise-close`: Delegates the action to the parent element. If no parent is found, it closes the element. `defer-otherwise-ignore`: Delegates the action to the parent element. If no parent is found, nothing is done. `ignore`: Prevents the element from closing and also blocks the parent element from closing in response to an outside interaction. - `onCloseAutoFocus` (`EventCallback`): Event handler called when auto-focusing on close. Can be prevented. - `onEscapeKeydown` (`((e: KeyboardEvent) => void)`): Callback fired when escape is pressed. - `onFocusOutside` (`((event: FocusEvent) => void)`): Callback fired when focus leaves the dismissible layer. - `onInteractOutside` (`InteractOutsideEventHandler`): Callback fired when an outside interaction event completes, which is either a `pointerup`, `mouseup`, or `touchend` event, depending on the user's input device. - `onOpenAutoFocus` (`EventCallback`): Event handler called when auto-focusing on open. Can be prevented. - `portalProps` (`PortalProps`): Props for the portal the content renders in: `to` (the element to render in, the body by default) and `disabled` (render in place). - `preventBodyPointerEvents` (`boolean`, default `true`): Whether to set `pointer-events: none` on the `` while the dialog is open. When `false` and a `Dialog.Overlay` is rendered, the overlay blocks pointer interaction with the page instead, which avoids restyling every element on the page when the dialog opens and closes. Without an overlay, the body is still blocked. Elements stacked above the overlay that aren't part of the dialog (toasts, a header with a higher `z-index`) receive pointer events when this is `false`. - `preventOverflowTextSelection` (`boolean`, default `true`): Passing `true` will prevent the overflow of text selection outside the element, provided the element is the top layer. - `preventScroll` (`boolean`, default `true`): Whether to prevent body scrolling when the content is open. - `restoreScrollDelay` (`number | null`, default `null`): The delay in milliseconds before the scrollbar is restored after closing the dialog. This is only applicable when using the `child` snippet for custom transitions and `preventScroll` is `true`. You should set this to a value greater than the transition duration to prevent content from shifting during the transition. - `showCloseButton` (`boolean`, default `true`): Show a close button in the corner. - `trapFocus` (`boolean`, default `false`): Whether focus is trapped within the focus scope. Props of `Dialog.Title`: - `level` (`1 | 2 | 3 | 4 | 5 | 6`): The heading level of the dialog title. Example: Confirm A dialog with a footer of actions. Dialog.Close closes it; focus returns to the trigger. For something that can't be undone, AlertDialog is the better fit. ```svelte Archive order Archive order 1042? It moves out of the list; you can restore it later. Cancel Archive ``` Example: Form A short form, closed from code with bind:open once it is saved. ```svelte

Project: {name}

Rename project
{ event.preventDefault(); const value = new FormData(event.currentTarget).get('name'); if (typeof value === 'string') name = value; open = false; }} > Rename project The name shows in the sidebar and in emails. Name
```