Skip to content

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.

#084

Confirmation

The destructive confirm and cancel pattern.

Reference #084 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Dialog, Button } from '@codeatlasdev/ui';
  import { Trash2 } from '@lucide/svelte';

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

<Button variant="destructive" onclick={() => ((confirmed = false), (open = true))}>
  {#snippet leading()}<Trash2 size={14} />{/snippet}
  Delete item
</Button>

<Dialog
  bind:open
  title="Delete this item?"
  description="This action cannot be undone. The item will be permanently removed from your workspace."
  size="sm"
>
  {#snippet actions()}
    <Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
    <Button variant="destructive" onclick={() => { confirmed = true; open = false; }}>Delete</Button>
  {/snippet}
</Dialog>

{#if confirmed}<p class="feedback" aria-live="polite">Item deleted.</p>{/if}

<style>
  .feedback { margin: 0; font-size: 13px; color: var(--ca-semantic-error); font-style: italic; }
</style>
#086

Info

Informational content with a single action.

Reference #086 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Dialog, Button } from '@codeatlasdev/ui';
  import { Info } from '@lucide/svelte';

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

<Button variant="outlined" onclick={() => (open = true)}>
  {#snippet leading()}<Info size={14} />{/snippet}
  View details
</Button>

<Dialog bind:open title="About this component">
  <p class="body">
    <strong>Dialog</strong> renders a native modal <code>&lt;dialog&gt;</code>. It traps focus
    (Tab cycles inside), closes on Escape and makes the page behind inert.
  </p>
  <p class="body">
    The overlay blurs the page while the panel uses a solid <code>--ca-surface-overlay</code>,
    so there is no double blur over the scrim.
  </p>
  {#snippet actions()}
    <Button variant="filled" onclick={() => (open = false)}>Got it</Button>
  {/snippet}
</Dialog>

<style>
  .body {
    font-size: var(--ca-font-size-body2);
    color: var(--ca-text-secondary);
    line-height: 1.6;
    margin: 0 0 10px;
  }
  .body:last-child { margin-bottom: 0; }
  .body strong { color: var(--ca-text-primary); }
  .body code {
    font-family: var(--ca-font-mono);
    font-size: 0.88em;
    color: var(--ca-brand-text);
    background: color-mix(in oklch, var(--ca-brand-main) 10%, transparent);
    padding: 1px 5px;
    border-radius: var(--ca-radius-xs);
  }
</style>
#085

Form

A dialog holding a form, at the md size.

Reference #085 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Dialog, Button, TextField, Select, Stack } from '@codeatlasdev/ui';

  let open = $state(false);
  let name = $state('');
  let email = $state('');
  let role = $state('viewer');
  const roleOpts = [
    { value: 'admin', label: 'Admin' },
    { value: 'editor', label: 'Editor' },
    { value: 'viewer', label: 'Viewer' },
  ];
</script>

<Button variant="filled" onclick={() => (open = true)}>Invite member</Button>

<Dialog bind:open title="Invite team member" size="md">
  <Stack gap="3.5">
    <TextField label="Full name" bind:value={name} placeholder="Ada Lovelace" />
    <TextField label="Email" type="email" bind:value={email} placeholder="[email protected]" />
    <Select label="Role" bind:value={role} options={roleOpts} />
  </Stack>
  {#snippet actions()}
    <Button variant="ghost" onclick={() => (open = false)}>Cancel</Button>
    <Button variant="filled" disabled={!name || !email} onclick={() => (open = false)}>Send invite</Button>
  {/snippet}
</Dialog>
#083

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
svelte
<script lang="ts">
  import { Dialog, Button } from '@codeatlasdev/ui';

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

<Button variant="outlined" onclick={() => (open = true)}>Open chromeless</Button>

<Dialog bind:open title="Preview" size="md" chromeless>
  <div class="media">
    <p>Edge-to-edge content. Close with Esc or by clicking outside.</p>
    <Button variant="filled" onclick={() => (open = false)}>Close</Button>
  </div>
</Dialog>

<style>
  .media {
    display: grid;
    gap: 12px;
    padding: 24px;
    justify-items: start;
    color: var(--ca-text-secondary);
    font-size: var(--ca-font-size-body2);
  }
  .media p { margin: 0; }
</style>
#087

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
svelte
<script lang="ts">
  import { Dialog, Button, TextField, Stack } from '@codeatlasdev/ui';

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

<Button variant="filled" onclick={() => (open = true)}>Open split</Button>

<Dialog bind:open title="Lead details" size="split" chromeless>
  <div class="media">Media / summary</div>
  <div class="form">
    <Stack gap="3.5">
      <TextField label="Full name" bind:value={name} placeholder="Ada Lovelace" />
      <TextField label="Email" type="email" bind:value={email} placeholder="[email protected]" />
      <Button variant="filled" onclick={() => (open = false)}>Save</Button>
    </Stack>
  </div>
</Dialog>

<style>
  .media {
    display: grid;
    place-items: center;
    min-height: 160px;
    background: color-mix(in oklab, var(--ca-brand-main) 12%, var(--ca-surface-overlay));
    color: var(--ca-text-secondary);
    font-size: var(--ca-font-size-body2);
  }
  .form { padding: 24px; overflow-y: auto; }
</style>

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.

#910

Configured split

splitSize, splitColumns and fullscreenBelow="sm": 66vw by 88svh, 2fr/3fr, full screen on phones.

Reference #910 · Pick in the gallery

Code
svelte
<script lang="ts">
  import { Dialog, Button, Stack } from '@codeatlasdev/ui';

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

<Button variant="filled" onclick={() => (open = true)}>Open lead</Button>

<Dialog
  bind:open
  title="Lead details"
  size="split"
  chromeless
  splitColumns="2fr 3fr"
  splitSize={{ width: 'min(66vw, 80rem)', height: 'min(88svh, 56rem)' }}
  fullscreenBelow="sm"
>
  <div class="map">Map</div>
  <div class="details">
    <Stack gap="3">
      <p class="name">Atlas Logistics</p>
      <Button variant="filled" onclick={() => (open = false)}>Close</Button>
    </Stack>
  </div>
</Dialog>

<style>
  .map {
    display: grid;
    place-items: center;
    min-height: 160px;
    background: color-mix(in oklab, var(--ca-brand-main) 12%, var(--ca-surface-overlay));
    color: var(--ca-text-secondary);
  }
  .details { padding: 24px; overflow-y: auto; }
  .name { margin: 0; color: var(--ca-text-primary); }
</style>

Props

PropTypeDefaultDescription
openbooleanfalseBindable open state.
titlestring–Header title. With chromeless it is the hidden accessible name.
descriptionstring–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.
splitColumnsstring'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.
inlinebooleanfalseRender 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.
chromelessbooleanfalseOmits header, description and actions; the body has no padding. title and description stay available to screen readers.
childrenSnippet–Dialog body.
actionsSnippet–Footer buttons.
onOpenChange(open: boolean) => void–Called whenever the open state changes.
classstring''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.