Dialog
@codeui/solid v0.3.0
A modal window over the page, for a decision that blocks the user.
When to use
Use a dialog for settings, or for a decision the user must make before they continue, such as deleting a snippet. The dialog traps focus, puts a scrim behind the panel, and returns focus to the opener when it closes.
When to choose another component
- Popover picks a value for one row. It has no scrim and does not block the page.
- Sheet holds a panel on a phone.
- Command menu finds an action by name.
- For an action the user can undo, skip the dialog. Run the action and offer undo in a toast.
Live demo
import { createSignal } from "solid-js";
import { Button, Dialog, DialogPanelContent, DialogPanelFooter } from "@codeui/solid";
export default function DialogBasic() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="negative" onClick={() => setOpen(true)}>
Delete snippet
</Button>
<Dialog open={open()} onOpenChange={setOpen} title="Delete snippet" size="sm">
<DialogPanelContent>
The snippet and its export history are removed. This cannot be undone.
</DialogPanelContent>
<DialogPanelFooter>
<div style={{ display: "flex", gap: "8px", "justify-content": "flex-end" }}>
<Button variant="secondary" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button variant="negative" onClick={() => setOpen(false)}>
Delete
</Button>
</div>
</DialogPanelFooter>
</Dialog>
</>
);
}Dialog renders the overlay, the panel, and a header with the title and a close button.
Put the body in DialogPanelContent and the actions in DialogPanelFooter. Close and Confirm sit on the right.
Anatomy
Tap a part to outline it in the demo.
- 01Trigger
dialog-trigger - 02Overlay
dialog-overlayclasses.overlay - 03Positioner
dialog-positionerclasses.positioner - 04DialogPanel
dialog-panelclasses.panel - 05Header
dialog-panel-titleclasses.header - 06Title
dialog-titleclasses.title - 07CloseButton
dialog-close-buttonclasses.closeButton - 08Description
dialog-descriptionclasses.description - 09DialogPanelContent
dialog-panel-contentclasses.class - 10DialogPanelFooter
dialog-panel-footerclasses.class - 11Sidebar
dialog-sidebarclasses.sidebar - 12Sidebar
dialog-sidebar-searchclasses.sidebarSearch - 13Nav
dialog-navclasses.nav - 14NavItem
dialog-nav-itemclasses.navItem - 15NavItem
dialog-nav-iconclasses.navIcon - 16Main
dialog-mainclasses.main - 17Section
dialog-sectionclasses.section - 18Section
dialog-section-titleclasses.sectionTitle - 19Section
dialog-section-contentclasses.sectionContent
| Export | Renders | classes key | data-cui | Role |
|---|---|---|---|---|
Root (parts only) | Nothing. Holds the open state | none | none | none |
Trigger (parts only) | button | none | dialog-trigger | Opens the dialog |
Portal | Nothing. Moves the content to mount | none | none | none |
Overlay | div | overlay | dialog-overlay | Layer behind the panel |
Positioner | div | positioner | dialog-positioner | Centers the panel and paints the scrim |
DialogPanel, Content | div | panel | dialog-panel | role="dialog" |
Header | div | header | dialog-panel-title | Row with the title and the close button |
Title | h2 | title | dialog-title | Accessible name of the dialog |
CloseButton | button | closeButton | dialog-close-button | Closes the dialog |
Description | p | description | dialog-description | Accessible description |
DialogPanelContent, Body | div | none, use class | dialog-panel-content | Scrolling content area |
DialogPanelFooter, Footer | div | none, use class | dialog-panel-footer | Row of actions |
Sidebar (parts only) | div | sidebar | dialog-sidebar | Left pane of a settings dialog |
Sidebar search wrapper | div | sidebarSearch | dialog-sidebar-search | Holds the search content |
Nav (parts only) | nav with a ul | nav | dialog-nav | Named list of sections |
NavItem (parts only) | li with a button | navItem | dialog-nav-item | One section. aria-current="page" when current |
NavItem icon | span | navIcon | dialog-nav-icon | Decorative icon, hidden from assistive technology |
Main (parts only) | div | main | dialog-main | Pane next to the sidebar |
Section (parts only) | section | section | dialog-section | A titled island, or a well |
Section title | h3 | sectionTitle | dialog-section-title | Heading of the section |
Section content | div | sectionContent | dialog-section-content | The island that holds rows or actions |
The header part carries dialog-panel-title, not dialog-header. Target it by that name.
Variants
Size
import { createSignal, For } from "solid-js";
import { Button, Dialog, DialogPanelContent } from "@codeui/solid";
const sizes = ["xs", "sm", "md", "lg", "xl", "full"] as const;
type Size = (typeof sizes)[number];
export default function DialogSizes() {
const [size, setSize] = createSignal<Size | null>(null);
return (
<>
<For each={sizes}>
{value => (
<Button variant="secondary" onClick={() => setSize(value)}>
{value}
</Button>
)}
</For>
<Dialog
open={size() !== null}
onOpenChange={open => !open && setSize(null)}
size={size() ?? undefined}
title={`Dialog size ${size()}`}
>
<DialogPanelContent>
The panel is as wide as the size allows. Press Escape or the close button to close it.
</DialogPanelContent>
</Dialog>
</>
);
}size sets the panel width: xs 24rem, sm 28rem, md 32rem, lg 48rem from the md breakpoint, xl 64rem from the lg breakpoint.
Below those breakpoints, lg and xl take the width of the viewport less the gutter. full covers the viewport with no radius.
Two sizes fit CodeImage's layouts:
settingsis 1000×680, for a sidebar beside a pane. On a smaller viewport it shrinks to fit, and at 768px and below it fills the viewport less the gutter.exportis 800 wide and as tall as its content. When it is taller than the viewport, the panel scrolls.
The positioner keeps an 8px gutter on every side, 16px around an export panel, so a dialog never touches the edge of a phone screen. Change it with the gutter theme variable.
Chrome
import { Button, Dialog, DialogPanelContent, DialogPanelFooter } from "@codeui/solid";
import { createSignal } from "solid-js";
export default function DialogInset() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
Delete snippet
</Button>
<Dialog open={open()} onOpenChange={setOpen} size="sm" chrome="inset" title="Delete index.tsx?">
<DialogPanelContent>The snippet and its export settings are removed from this device.</DialogPanelContent>
<DialogPanelFooter>
<Button variant="secondary" onClick={() => setOpen(false)}>
Cancel
</Button>
<Button variant="negative" onClick={() => setOpen(false)}>
Delete
</Button>
</DialogPanelFooter>
</Dialog>
</>
);
}chrome sets how the header sits in the panel. bar, the default, puts the title in a 56px bar with a divider under it.
inset puts the title in the panel padding with no divider. The panel gets 20px padding, a 20px gap between its children, and 24px corners. The close button becomes a small ghost icon button.
A settings panel keeps 14px corners, because its panes reach the edges.
With inset, Footer becomes a right-aligned row of actions that stacks at 768px and below. Close and Confirm sit on the right.
Split body and sections
import {
Button,
Checkbox,
OptionCardGroup,
SegmentedControl,
SegmentedControlItem,
SettingsGroup,
SettingsRow,
Stack,
} from "@codeui/solid";
import * as Dialog from "@codeui/solid/dialog/parts";
import { createSignal, For } from "solid-js";
import { type JSX } from "@solidjs/web";
import { CopyIcon, DownloadIcon, ExternalIcon, LayersIcon, SlidersIcon, TextIcon } from "../build-settings/icons";
const formats = [
{ value: "png", label: "PNG", description: "Sharp text, transparent corners" },
{ value: "jpeg", label: "JPEG", description: "Smaller file, no transparency" },
{ value: "svg", label: "SVG", description: "Vector, sharp at any size" },
];
const scales = ["1", "2", "3", "6"];
const more: { label: string; description: string; action: string; icon: () => JSX.Element; disabled?: boolean }[] = [
{ label: "Open in new tab", description: "See it before you save it", action: "Open", icon: ExternalIcon },
{ label: "Export one image per tab", description: "Needs two tabs or more", action: "Export", icon: LayersIcon, disabled: true },
{ label: "Copy alt text", description: "Text for screen readers and social posts", action: "Copy", icon: TextIcon },
{ label: "Export settings…", description: "Format, scale and tabs for every export", action: "Edit", icon: SlidersIcon },
];
export default function DialogExport() {
const [format, setFormat] = createSignal("png");
const [scale, setScale] = createSignal("3");
const name = () => formats.find(item => item.value === format())?.label;
return (
<Dialog.Root>
<Dialog.Trigger as={Button} variant="primary" leftIcon={<DownloadIcon />}>
Export
</Dialog.Trigger>
<Dialog.Portal>
<Dialog.Overlay />
<Dialog.Positioner size="export">
<Dialog.Content size="export" chrome="inset">
<Dialog.Header>
<Dialog.Title>Export</Dialog.Title>
<Dialog.CloseButton aria-label="Close export" />
</Dialog.Header>
<Dialog.Body layout="split">
<Dialog.Section variant="well" aria-label="Preview">
<Preview />
</Dialog.Section>
<Stack direction="column" gap="3">
<SettingsGroup>
<SettingsRow label="Format" layout="wide">
{control => (
<OptionCardGroup {...control} orientation="vertical" items={formats} value={format()} onChange={setFormat} />
)}
</SettingsRow>
<SettingsRow label="Scale" description={`${593 * Number(scale())} × ${469 * Number(scale())} px`} layout="wide">
{control => (
<SegmentedControl {...control} size="sm" fluid value={scale()} onChange={setScale}>
<For each={scales}>{value => <SegmentedControlItem value={value}>{value}x</SegmentedControlItem>}</For>
</SegmentedControl>
)}
</SettingsRow>
</SettingsGroup>
<Checkbox size="sm" label="Remember as default" />
</Stack>
</Dialog.Body>
<Dialog.Footer>
<Button size="sm" variant="secondary" leftIcon={<CopyIcon />}>
Copy image
</Button>
<Button size="sm" variant="primary" leftIcon={<DownloadIcon />}>
Download {name()} · {scale()}x
</Button>
</Dialog.Footer>
<Dialog.Section variant="well" title="More">
<For each={more}>
{item => (
<SettingsRow label={item.label} description={item.description} picture={<item.icon />} compactControl>
{control => (
<Button aria-describedby={control["aria-labelledby"]} size="sm" variant="secondary" ghost disabled={item.disabled}>
{item.action}
</Button>
)}
</SettingsRow>
)}
</For>
</Dialog.Section>
</Dialog.Content>
</Dialog.Positioner>
</Dialog.Portal>
</Dialog.Root>
);
}
/** A schematic of the snippet in its own colours: the gradient frame, the window and its code. */
function Preview() {
return (
<svg viewBox="0 0 400 300" width="100%" role="img" aria-label="Preview of index.tsx">
<defs>
<linearGradient id="export-demo-frame" x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stop-color="#e0915c" />
<stop offset="0.55" stop-color="#c35ad6" />
<stop offset="1" stop-color="#7c3aed" />
</linearGradient>
</defs>
<rect width="400" height="300" rx="8" fill="url(#export-demo-frame)" />
<rect x="60" y="62" width="280" height="176" rx="12" fill="#16161a" />
<circle cx="82" cy="84" r="5" fill="#ff5f57" />
<circle cx="98" cy="84" r="5" fill="#febc2e" />
<circle cx="114" cy="84" r="5" fill="#28c840" />
<g stroke="#c792ea" stroke-opacity="0.7" stroke-width="7" stroke-linecap="round">
<path d="M82 118h150M98 140h110M98 162h170M82 184h70M98 206h120" />
</g>
</svg>
);
}layout="split" on Body puts its first child beside its second, at 1.1fr to 1fr with a 20px gap. At 768px and below the two stack.
Put the preview in a Section with variant="well". The well is an island: the canvas fill, 16px corners, and 12px padding.
A well with a title shows the title inside the island in small secondary text. columns={2} lays its content out in two columns, one at 768px and below. The export dialog uses one for the More actions.
The options are kit components too. A SettingsGroup holds a SettingsRow with layout="wide" for the format cards and one for the scale, and the More well holds a SettingsRow per action with its icon in picture. The preview is an inline SVG: a schematic of the snippet in its own colours. The demo has no CSS of its own.
Title and description
import { createSignal } from "solid-js";
import { Badge, Button, Dialog, DialogPanelContent, Kbd } from "@codeui/solid";
export default function DialogTitleAndDescription() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
Export as video
</Button>
<Dialog
open={open()}
onOpenChange={setOpen}
size="md"
title={
<span style={{ display: "inline-flex", gap: "8px", "align-items": "center" }}>
Export as video <Badge tone="info">Beta</Badge>
</span>
}
description={
<>
Renders the timeline as MP4. Press <Kbd>Esc</Kbd> to cancel.
</>
}
>
<DialogPanelContent>The export runs in the background. You can keep editing.</DialogPanelContent>
</Dialog>
</>
);
}title and description take JSX, so a title can carry a badge and a description can carry a keycap.
The title names the dialog through aria-labelledby. The description renders in a p element, so keep it to inline content.
Without title, the header and its close button do not render. Then give the dialog an aria-label.
Footer and long content
import { createSignal, For } from "solid-js";
import { Button, Dialog, DialogPanelContent, DialogPanelFooter } from "@codeui/solid";
const changes = Array.from({ length: 40 }, (_, i) => `Snippet ${i + 1} moved to the "Archive" folder`);
export default function DialogOverflow() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
Show import log
</Button>
<Dialog open={open()} onOpenChange={setOpen} title="Import log" size="md">
<DialogPanelContent>
<ul style={{ margin: 0, "padding-left": "16px" }}>
<For each={changes}>{change => <li>{change}</li>}</For>
</ul>
</DialogPanelContent>
<DialogPanelFooter>
<div style={{ display: "flex", "justify-content": "flex-end" }}>
<Button variant="primary" onClick={() => setOpen(false)}>
Done
</Button>
</div>
</DialogPanelFooter>
</Dialog>
</>
);
}DialogPanelContent scrolls when the content is taller than the viewport. The header and the footer stay in place.
DialogPanelFooter adds padding only. Lay out the buttons inside it with your own flex row.
Classes
import { createSignal } from "solid-js";
import { Button, Dialog, DialogPanelContent } from "@codeui/solid";
import "./classes.css";
export default function DialogClasses() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
Open share settings
</Button>
<Dialog
open={open()}
onOpenChange={setOpen}
size="sm"
title="Share snippet"
description="Anyone with the link can view the snippet."
classes={{
panel: "dialog-classes-demo-panel",
header: "dialog-classes-demo-header",
description: "dialog-classes-demo-description",
}}
>
<DialogPanelContent>The link stays valid until you delete the snippet.</DialogPanelContent>
</Dialog>
</>
);
}classes sets a class on each part that Dialog renders. App CSS is unlayered, so it wins over the kit styles in the cui layer with one class.
To style DialogPanelContent or DialogPanelFooter, pass class to them directly.
Mount
import { createSignal, Show } from "solid-js";
import { Button, Dialog, DialogPanelContent } from "@codeui/solid";
export default function DialogMount() {
const [open, setOpen] = createSignal(false);
const [host, setHost] = createSignal<HTMLElement>();
return (
<div ref={setHost} data-demo-host="editor">
<Button variant="secondary" onClick={() => setOpen(true)}>
Open in the editor host
</Button>
<Show when={host()}>
{node => (
<Dialog open={open()} onOpenChange={setOpen} mount={node()} size="sm" title="Rename snippet">
<DialogPanelContent>
This dialog is portaled into the element marked data-demo-host, not into document.body.
</DialogPanelContent>
</Dialog>
)}
</Show>
</div>
);
}mount sets the node the dialog is portaled into. The default is document.body.
Use it to keep the dialog inside a themed subtree, such as an element with data-cui-theme, or inside a shadow root.
The positioner is position: fixed, so the dialog still covers the viewport.
States
Controlled and uncontrolled
The ready Dialog has no trigger, so you control it with open and onOpenChange.
For an uncontrolled dialog, compose the styled parts with a Trigger and leave open unset. The settings layout below does this.
Motion
The panel pops in from scale(0.96) with a fade over 200ms, and leaves toward scale(0.98) over 120ms. The scrim fades in and out with it.
A dialog opened or closed from the keyboard does not move. Kit parts mark it with data-motion="none". So do opens from code with no pointer press before them.
Pointer opens and closes animate. Set motion="none" on Dialog or Root to never animate.
With reduced motion, the panel and the scrim only fade.
Focus return without a trigger
import { createSignal } from "solid-js";
import { Button, Dialog, DialogPanelContent } from "@codeui/solid";
export default function DialogFocusReturn() {
const [open, setOpen] = createSignal(false);
return (
<>
<Button variant="secondary" onClick={() => setOpen(true)}>
Rename
</Button>
<Button variant="secondary" onClick={() => setOpen(true)}>
Duplicate
</Button>
<Dialog open={open()} onOpenChange={setOpen} size="sm" title="Snippet actions">
<DialogPanelContent>
Close this dialog with Escape. Focus goes back to the button that opened it.
</DialogPanelContent>
</Dialog>
</>
);
}Kobalte returns focus only to its own trigger part. The kit Content part adds the rest.
When the dialog opens, Content records the focused element. When it closes, focus goes back to that element.
So two buttons can open the same dialog, and focus returns to the one the user pressed.
Focus does not return when one of these is true:
- your
onCloseAutoFocuscallspreventDefault(); - the dialog has a
Triggerpart, so Kobalte handles the return; - a non-modal dialog closed because the user clicked or focused outside it;
- the recorded element is no longer in the document.
Ready API
Dialog
Renders the portal, overlay, positioner, panel, and, when title is set, the header.
Prop
Type
Inherited from Kobalte's dialog. Dialog also passes onFocusOutside and onInteractOutside to the panel.
Prop
Type
DialogPanel
The Content part under another name. Use it when you compose your own dialog from parts.
Prop
Type
DialogPanelContent
The Body part. A div with the content padding that scrolls on overflow. It takes every div attribute.
DialogPanelFooter
The Footer part. A div with the content padding. With size="full" it sticks to the bottom of the panel. It takes every div attribute.
Styled parts API
Import the parts from @codeui/solid/dialog/parts. Each part carries the kit styles and a data-cui attribute, and wraps the matching Kobalte primitive.
import { createSignal } from "solid-js";
import { Button } from "@codeui/solid";
import * as D from "@codeui/solid/dialog/parts";
export default function DialogParts() {
const [open, setOpen] = createSignal(false);
return (
<D.Root open={open()} onOpenChange={setOpen}>
<D.Trigger as={Button} variant="secondary">
Export as video
</D.Trigger>
<D.Portal>
<D.Overlay />
<D.Positioner size="sm">
<D.Content size="sm">
<D.Header>
<D.Title>Export as video</D.Title>
<D.CloseButton />
</D.Header>
<D.Description>Pick a format and a frame rate.</D.Description>
<D.Body>The export runs in the background. You can keep editing.</D.Body>
<D.Footer>
<div style={{ display: "flex", "justify-content": "flex-end" }}>
<Button variant="primary" onClick={() => setOpen(false)}>
Start export
</Button>
</div>
</D.Footer>
</D.Content>
</D.Positioner>
</D.Portal>
</D.Root>
);
}Build a custom layout
import { createSignal, For, Show } from "solid-js";
import { Button, SettingsGroup, SettingsRow, Switch } from "@codeui/solid";
import * as D from "@codeui/solid/dialog/parts";
import { DownloadIcon, FlaskIcon, PaletteIcon, SlidersIcon } from "../build-settings/icons";
const sections = [
{ name: "General", icon: SlidersIcon, group: "Editor", label: "Line numbers", description: "Show a number before each line of code." },
{ name: "Appearance", icon: PaletteIcon, group: "Motion", label: "Reduce motion", description: "Fade overlays instead of moving them." },
{ name: "Export", icon: DownloadIcon, group: "Image", label: "Transparent background", description: "Keep the area outside the frame clear." },
{ name: "Experiments", icon: FlaskIcon, group: "Rendering engine", label: "Takumi", description: "Use the experimental Takumi engine for image exports." },
];
export default function DialogSettingsLayout() {
const [current, setCurrent] = createSignal(sections[0]);
return (
<D.Root>
<D.Trigger as={Button} variant="secondary">
Open settings
</D.Trigger>
<D.Portal>
<D.Overlay />
<D.Positioner size="settings">
<D.Content size="settings" chrome="inset">
<D.Sidebar>
<D.Nav aria-label="Settings sections">
<For each={sections}>
{item => (
<D.NavItem icon={<item.icon />} current={current() === item} onClick={() => setCurrent(item)}>
{item.name}
</D.NavItem>
)}
</For>
</D.Nav>
</D.Sidebar>
<D.Main>
<D.Header>
<D.Title>Settings / {current().name}</D.Title>
<D.CloseButton aria-label="Close settings" />
</D.Header>
<D.Body>
{/* Keyed, so each section gets its own switch. */}
<Show when={current()} keyed>
{item => (
<SettingsGroup title={item.group}>
<SettingsRow label={item.label} description={item.description} compactControl>
{control => <Switch {...control} />}
</SettingsRow>
</SettingsGroup>
)}
</Show>
</D.Body>
</D.Main>
</D.Content>
</D.Positioner>
</D.Portal>
</D.Root>
);
}This settings dialog follows Inkstone's settings dialog: a 232px sidebar with the sections, a breadcrumb title, a close button, and no footer.
Content with a Sidebar child lays out in two panes and drops its padding. Each pane holds its own. At 768px and below, the header moves to the top, the sections wrap into rows of three, and the body fills the rest.
The title is still the Title part, so the breadcrumb names the dialog. The body is still the Body part, so the rows scroll.
Put each group of rows in a SettingsGroup: a title over one island, with the rows touching inside it. The Build settings pattern adds a search field and CodeImage's six sections.
Root
Kobalte's Dialog root. Holds the open state and takes every Kobalte root option, such as open, defaultOpen, onOpenChange, and modal. It renders no element.
It also records whether the user last pressed a pointer or a key, so Positioner and Content know whether to animate.
Prop
Type
Trigger
Kobalte's Dialog.Trigger. A button that opens the dialog. Use as={Button} for a kit button. Kobalte returns focus to it on close.
Portal
Kobalte's Dialog.Portal. Takes mount. It renders no element.
Overlay
Kobalte's Dialog.Overlay. A fixed div behind the panel.
Positioner
A fixed div that centers the panel and paints the scrim from --cui-surface-scrim. It is not a Kobalte part.
Prop
Type
Content
Kobalte's Dialog.Content. The panel. It adds focus return without a trigger, described under States.
Prop
Type
Header
A div that lays out the title and the close button in one row. With chrome="bar" it has a divider under it. It is not a Kobalte part.
Title
Kobalte's Dialog.Title. An h2 that names the dialog.
Description
Kobalte's Dialog.Description. A p that describes the dialog.
CloseButton
Kobalte's Dialog.CloseButton, rendered as an extra-small secondary IconButton with a close icon. With chrome="inset" it is a small ghost icon button. size, variant, and ghost override both defaults.
Prop
Type
Body
A div with the content padding that scrolls on overflow. The same component as DialogPanelContent.
With chrome="inset" it has no padding of its own. Inside Main it is a column of sections with 24px gaps that scrolls.
Prop
Type
Footer
A div with the content padding. The same component as DialogPanelFooter. With chrome="inset" it is a right-aligned row of actions.
Sidebar
A 232px column on the panel's own surface, for the sections of a settings dialog. Put a Nav in it.
search renders above the navigation, in a wrapper with the same side padding as the items.
Prop
Type
Nav
A nav that holds a ul of NavItems. Give it an aria-label.
The arrow keys move focus between the items and wrap at the ends. Home and End jump to the first and last item. Each item stays in the tab order.
Prop
Type
NavItem
A button in an li. 36px tall, 40px at 768px and below, with 10px corners.
current sets aria-current="page" and gives the item the field fill. Select a section in onClick. Enter and Space click the focused button.
Prop
Type
Main
A div that fills the pane next to the Sidebar, on the page surface. Put the Header and the Body in it. It takes every div attribute.
Section
A section with an optional h3 title and a content div. variant="group", the default, puts the title over one island whose rows touch. variant="well" makes the section the island.
Prop
Type
Styles export
dialogStyles
dialogStyles from @codeui/solid/dialog/parts maps each part name to a function that returns its class string.
Call dialogStyles.panel(), body(), and section() for the corresponding part classes.
The styles read data-size and data-chrome on the panel, data-layout on the body, and data-variant and data-columns on a section. Set them when you apply the classes to your own elements.
trigger, title, and closeButton return an empty string, because those parts take their look from other components.
Call a style function when you render the Kobalte primitive yourself and want the kit look. Add the matching data-cui value from dialogParts too, so selectors that target the part still match.
positioner and panel include the class that sets the dialog's local variables. Apply one of them to an ancestor of the other parts.
Accessibility
Keyboard
| Key | Action |
|---|---|
| Tab | Moves focus to the next focusable element in the panel. Wraps from the last to the first. |
| Shift+Tab | Moves focus to the previous focusable element in the panel. Wraps from the first to the last. |
| Escape | Closes the dialog. If a menu, popover, or select is open inside it, Escape closes that layer first. |
| Enter, Space | On the Trigger part, opens the dialog. On a NavItem, selects that section. |
| ArrowDown, ArrowRight | In a Nav, moves focus to the next item. Wraps from the last to the first. |
| ArrowUp, ArrowLeft | In a Nav, moves focus to the previous item. Wraps from the first to the last. |
| Home, End | In a Nav, moves focus to the first or the last item. |
ARIA
- The panel has
role="dialog". Kobalte links it toTitlewitharia-labelledbyand toDescriptionwitharia-describedby. - The
Triggerpart hasaria-haspopup="dialog",aria-expanded, andaria-controls. - The close button's accessible name is
close. Change it withcloseLabelonDialogoraria-labelonCloseButton. - A modal dialog hides the rest of the page from assistive technology while it is open.
Navis anavlandmark named by itsaria-label, with a list of buttons. The current item hasaria-current="page".- A
NavItemicon isaria-hidden. The label names the button.
Focus
On open, focus moves to the first focusable element in the panel. In the ready Dialog that is the close button.
On close, focus returns to the Trigger part, or to the element that had focus when the dialog opened.
To focus a specific field on open, call preventDefault() in onOpenAutoFocus and focus it yourself. On a phone, do not focus a text field on open.
The settings demos focus the current NavItem this way, not the search field.
SSR notes
An open or force-mounted dialog includes its overlay and panel in server HTML at the Portal declaration. Hydration adopts those nodes and moves them to mount, or document.body by default. Closed dialogs omit their content unless force-mounted. Place Portal in a flow-content context that can contain the dialog markup.
Positioner and the size classes are plain class strings, so they are the same on the server and the client.
IDs for the title and the description come from Solid's createUniqueId, so they match between server and client.
Theming hooks
Dialog reads these --cui-* variables. See Tokens for the defaults.
| Variable | Used for |
|---|---|
--cui-surface-dialog | Panel fill |
--cui-shadow-dialog | Panel shadow |
--cui-text-dialog | Body and description text |
--cui-text-dialog-title | Title text |
--cui-border-dialog-title, --cui-border-width | Divider under the header |
--cui-surface-scrim | Scrim behind the panel |
--cui-radius-lg | Panel radius |
--cui-radius-dialog | Panel radius with chrome="inset", except settings |
--cui-space-6 | Panel padding |
--cui-space-5 | Panel padding and gap with chrome="inset", split body gap |
--cui-space-2, --cui-space-4 | Gutter around the panel, and around an export panel |
--cui-surface-panel | Main fill. In light mode, the current NavItem fill |
--cui-surface-canvas | Section island fill. In light mode, the Sidebar fill |
--cui-surface-input | Current NavItem fill |
--cui-text-muted, --cui-text-default | NavItem text, idle and current |
--cui-radius-card, --cui-radius-nav | Section island and NavItem corners |
--cui-focus-width, --cui-focus-color, --cui-focus-offset | NavItem focus ring |
--cui-font-size-lg, --cui-font-weight-medium | Title type |
--cui-motion-duration-panel, --cui-motion-duration-fast, --cui-motion-ease-out | Open and close animation of the panel and the scrim |
dialogThemeVars from @codeui/solid/dialog/parts holds the dialog's local variables. Set them on the panel with a vanilla-extract class (vars) or assignInlineVars to tune one dialog:
| Variable | Default | Used for |
|---|---|---|
gutter | --cui-space-2, --cui-space-4 with export | Space between the panel and the viewport edges |
width | 62.5rem with settings, 50rem with export | Panel width before the viewport caps it |
height | 42.5rem with settings | Panel height before the viewport caps it |
sidebarBackground | --cui-surface-dialog | Sidebar fill |
navCurrentBackground | --cui-surface-input | Current NavItem fill |
mainBackground | --cui-surface-panel | Main fill |
islandBackground | --cui-surface-canvas | Section island fill |
splitColumns | minmax(0, 1.1fr) minmax(0, 1fr) | Columns of a split body |
Composition examples
- Nest overlays puts a segmented control and a menu inside a dialog and shows where Escape goes.
- Compose styled parts compares the ready component, the parts, and Kobalte with kit classes.
- Build settings builds the full settings dialog.
Related
- Popover anchors to a trigger and has no scrim.
- Sheet slides up from the bottom on a phone.
- Choose ready components or parts explains the three layers.