Feedback
Dialog
A second-layer modal. The overlay blurs the page while the panel uses a solid surface.
<script>
import { Dialog, Button } from "@codeatlasdev/ui";
let open = $state(false);
</script>
<Dialog bind:open title="Confirm" description="This cannot be undone.">
{#snippet actions()}
<Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
<Button variant="destructive" onclick={remove}>Delete</Button>
{/snippet}
</Dialog>
Submitting a form from the footer. The actions footer sits outside the dialog body, so a submit button there is not inside your <form>. Give the form an id and name it on the button with form: Enter in a field and the button then both submit it, with no onclick that repeats the handler.
<script>
import { Dialog, Button } from "@codeatlasdev/ui";
let open = $state(false);
const add = (e) => { e.preventDefault(); open = false; };
</script>
<Dialog bind:open title="Add deal">
<form id="add-deal" onsubmit={add}>
<input name="title" aria-label="Title" />
</form>
{#snippet actions()}
<Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
<Button type="submit" form="add-deal">Add</Button>
{/snippet}
</Dialog>
The dialog renders a native modal <dialog> opened with showModal(): the page behind is inert, focus is trapped, scrolling is locked and Escape closes it. Clicking the overlay closes it too. For decisions that need an explicit answer use AlertDialog. On phones, prefer Sheet for bottom-anchored content.
Confirmation
The destructive confirm and cancel pattern.
Reference #084 · Pick in the gallery
Code
Info
Informational content with a single action.
Reference #086 · Pick in the gallery
Code
Form
A dialog holding a form, at the md size.
Reference #085 · Pick in the gallery
Code
Chromeless
No header, description or actions, and the body has no padding. The title becomes the visually hidden accessible name.
Reference #083 · Pick in the gallery
Code
Split
size="split" is 1100 by 720 with two columns from the md breakpoint (900px) and a single column below it. Combine it with chromeless.
Reference #087 · Pick in the gallery
Code
Configure the split: splitSize, splitColumns, fullscreenBelow. splitSize={{ width, height }} takes any CSS length (min(66vw, 80rem)), splitColumns="2fr 3fr" sets the column ratio and fullscreenBelow="sm" (600px) or "md" (900px) makes the dialog exactly the viewport (--ca-vh) with square corners and the safe-area inset as padding. The props set the tokens --ca-dialog-split-width, --ca-dialog-split-height and --ca-dialog-split-columns, so a style or class on an ancestor works too. Defaults are unchanged. Do not write selectors against .ca-dialog--split or .ca-dialog__body.
Configured split
splitSize, splitColumns and fullscreenBelow="sm": 66vw by 88svh, 2fr/3fr, full screen on phones.
Reference #910 · Pick in the gallery
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | false | Bindable open state. |
title | string | – | Header title. With chromeless it is the hidden accessible name. |
description | string | – | Subtitle below the title. |
size | 'sm' | 'md' | 'lg' | 'xl' | 'split' | 'md' | Width: 400, 480, 600 or 820px. split is 1100 by 720 in two columns from 900px. |
splitSize | { width?: string; height?: string } | – | size="split" panel box, any CSS length. Default 1100 by 720 capped to the viewport. Sets --ca-dialog-split-width and --ca-dialog-split-height. |
splitColumns | string | '1fr 1fr' | size="split" body grid-template-columns from 900px, for example '2fr 3fr'. Sets --ca-dialog-split-columns. |
fullscreenBelow | 'sm' | 'md' | – | Any size: below 600px (sm) or 900px (md) the dialog is exactly the viewport, square corners, safe-area padding kept. Focus trap and Escape unchanged. |
inline | boolean | false | Render inside its container instead of the top layer: position: absolute over the nearest positioned ancestor, no scrim over the page, no scroll lock, no focus trap, no inert page; Escape closes it only from inside. Takes the tokens of its container, so it follows a data-preset or data-theme-scope island. |
chromeless | boolean | false | Omits header, description and actions; the body has no padding. title and description stay available to screen readers. |
children | Snippet | – | Dialog body. |
actions | Snippet | – | Footer buttons. |
onOpenChange | (open: boolean) => void | – | Called whenever the open state changes. |
class | string | '' | Extra classes on the panel. |
Layers
Inline layers. inline on Dialog, Sheet, Drawer, Popover, DropdownMenu and Toaster renders the overlay where it is declared instead of in the top layer. It is position: absolute inside the nearest positioned ancestor (give the container position: relative), is never moved to <body>, never calls showModal() or showPopover(), never joins the layer stack, locks no scroll, traps no focus and makes nothing inert. Because it stays in the DOM subtree, it resolves the tokens of its container: put it inside a data-preset="violet" or data-theme-scope="dark" island (a theme preview, an embedded editor, a docs frame) and it wears that island’s theme, which a top-layer overlay never can. A dialog has no scrim in this mode. Escape closes an inline layer only while focus is inside it; a press elsewhere never does, so the page behind stays fully interactive. Use it for contained surfaces, not for the app’s real modals: a modal that must block the page stays the default.
<div class="stage" data-preset="violet">
<Dialog inline bind:open title="Rename review">…</Dialog>
<Toaster inline />
</div>
<style>.stage { position: relative; overflow: hidden; }</style>
openLayer(el, { kind, inline: true }) is the same switch for your own layers.
Dialogs, sheets, drawers, menus, popovers and tooltips share one layer stack. Modals are native <dialog> elements opened with showModal(); menus, popovers and tooltips are popover elements. Both live in the browser’s top layer, so a layer opened later is always on top: there is no z-index to manage, and a menu inside a dialog just works. Anchored layers use CSS anchor positioning where the browser supports it and fall back to Floating UI elsewhere.
Escape and outside presses go to the topmost layer only, so a menu inside a dialog closes first and the dialog on the next press. A layer stops being the topmost one the moment its open turns false, not when its exit animation ends: an Escape pressed while a confirm dialog is fading out reaches the drawer underneath. A menu that was already open when a modal opened ranks above that modal, so the first Escape closes the menu and the second the dialog. Focus returns to the trigger when a layer closes.
An open modal makes the rest of the page inert (no pointer, no Tab, no screen reader), and that includes top-layer popovers that live outside it. So a menu, select list, popover or tooltip is mounted inside the topmost open modal while it is open and goes back to where it was declared when it closes. This also holds when the modal opens after the popover (a shortcut opening a dialog over an open menu): the popover moves into the new modal and is shown again above it, and when a modal closes first its popovers are handed to the next modal or put back. Do not give a layer a z-index to fight this: it has no effect in the top layer.
Hover-opened UI never opens under a modal. Tooltip, HoverCard and NavigationMenuItem ignore pointer movement while a modal layer is open, unless the trigger itself lives inside the topmost modal (a tooltip on a dialog button still works). One already open when the modal opens is adopted by it, as above. A menu submenu needs no gate: its trigger is inside a menu, and a menu open under a modal is adopted into it. Gate your own hover or edge UI (an edge peek, a rail flyout, a custom hover panel) with the layers store instead of a z-index:
<script lang="ts">
import { layers } from "@codeatlasdev/ui";
let peek = $state(false);
// Never open under a dialog; close if one opens meanwhile.
$effect(() => { if (layers.modalOpen) peek = false; });
</script>
<div class="edge" onpointerenter={() => { if (!layers.modalOpen) peek = true; }}></div>
layers.modalOpen is reactive and true while a modal layer (not one already closing) is open. layers.blocks(trigger) is the same but false for a trigger inside the topmost modal, so a panel that lives in a dialog keeps working.
A host that draws outside the DOM (a native view over a webview) can follow the stack with onLayerChange. It fires on every open and close with the open layers, bottom to top, and their rectangles, and returns the function that unsubscribes:
import { onLayerChange, type LayerChange } from "@codeatlasdev/ui";
const stop = onLayerChange((change: LayerChange) => {
nativeView.setParked(change.count > 0);
// change.layers: LayerInfo[], bottom to top
// each LayerInfo is { kind: LayerKind, rect: DOMRect }
});
The same signal is a layerchange CustomEvent on document, with the detail as event.detail. LayerChange is { layers: LayerInfo[]; count: number; modal: boolean }, where modal is true while at least one modal layer is open. LayerKind is "modal" for Dialog, AlertDialog, Drawer and Sheet, "popover" for menus and popovers, and "hint" for tooltips. All three types are exported from @codeatlasdev/ui.