Dialog
A window over the page that holds one task, such as an edit, a form or a confirmation, and keeps the reader in it until the task is done or dismissed.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';export default function DialogBasic() { const [open, setOpen] = useState(false); const [email, setEmail] = useState('ap@northwindtraders.com'); const [draft, setDraft] = useState(email); return ( <Inline align="center" gap={3}> <Text size="sm">{email}</Text> <Dialog open={open} onOpenChange={(next) => { if (next) setDraft(email); setOpen(next); }} > <DialogTrigger render={(props) => ( <Button {...props} size="sm" tone="secondary" variant="outline"> Edit billing email </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Billing email</DialogTitle> <DialogDescription> Invoices and payment receipts for Northwind Traders go to this address. </DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Email</FieldLabel> <TextField type="email" value={draft} onValueChange={setDraft} /> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => { setEmail(draft); setOpen(false); }} > Save </Button> </DialogFooter> </DialogContent> </Dialog> </Inline> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Dialog, DialogBody, DialogClose, DialogContent, DialogDefaultsProvider, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@slotted/react';Sizes
size sets the panel’s maximum width to one of five steps: sm (32rem) for one field or one question, md (the default: the form measure, 40rem, plus the panel’s inline padding) for a form, lg (48rem) for a record with a table, xl (56rem) for two columns, and full for the whole layer less its padding. --slotted-dialog-measure-sm, -md, -lg and -xl retune one step; --slotted-dialog-measure sets every step, for a width the steps do not hold.
import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogHeader, type DialogSize, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';const SIZES: { size: DialogSize; title: string; body: string }[] = [ { size: 'sm', title: 'Rename warehouse', body: 'Small, 24rem: one field or one question.', }, { size: 'md', title: 'Edit customer', body: 'Medium, 32rem, the default: a short form of one column.', }, { size: 'lg', title: 'Invoice INV-2041', body: 'Large, 42rem: a record with a table of line items.', }, { size: 'xl', title: 'Compare price lists', body: 'Extra large, 56rem: two columns side by side.', }, { size: 'full', title: 'Shipment manifest', body: 'Full: the whole layer less its padding, for a document.', },];export default function DialogSizes() { return ( <Inline gap={2}> {SIZES.map((option) => ( <Dialog key={option.size} size={option.size}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {option.size} </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>{option.title}</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Text size="sm">{option.body}</Text> </DialogBody> </DialogContent> </Dialog> ))} </Inline> );}Placement
placement="top" holds the panel near the top of the screen instead of centering it. Use it for content that grows while the reader types, such as a note or a comment: a centerd panel moves up by half of every new line.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Textarea } from '@slotted/react/textarea';export default function DialogPlacement() { const [open, setOpen] = useState(false); return ( <Dialog open={open} onOpenChange={setOpen} placement="top"> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Add a note </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Note on order SO-1182</DialogTitle> <DialogDescription>The warehouse team sees the note on the pick list.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Note</FieldLabel> <Textarea rows={3} maxRows={12} placeholder="Leave at the loading dock after 2 pm." /> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => setOpen(false)}>Add note</Button> </DialogFooter> </DialogContent> </Dialog> );}Long content
With the default scroll="content", the panel never grows past the window: the body scrolls and the header and footer stay, so the actions are always in reach. scroll="viewport" lets the whole panel grow and scrolls the layer instead, for a document that is read rather than acted on.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const ITEMS = Array.from({ length: 24 }, (_, index) => ({ sku: `NW-${String(4100 + index * 7)}`, name: [ 'Chai, 10 boxes', 'Aniseed syrup, 12 bottles', 'Cajun seasoning, 48 jars', 'Olive oil, 36 bottles', 'Dried pears, 12 packs', 'Curry sauce, 12 jars', ][index % 6],}));const TERMS = [ 'Prices are in US dollars and exclude sales tax, which is added at the rate of the delivery address.', 'Payment is due 30 days from the invoice date. Balances unpaid after 45 days accrue interest at 1% a month.', 'Goods travel at the risk of Northwind Traders until they are signed for at the delivery address.', 'Damaged goods are reported within 5 business days of delivery, with photos of the packaging and the label.', 'Returns of undamaged goods are accepted within 30 days and are refunded less a 10% restocking fee.', 'Orders above $5,000 may be split into several shipments, each invoiced when it leaves the warehouse.', 'Either party may end a standing order with 14 days of written notice; shipments already picked are invoiced.', 'These terms are governed by the law of the State of Washington.',];export default function DialogScroll() { const [open, setOpen] = useState(false); return ( <Inline gap={2}> <Dialog open={open} onOpenChange={setOpen}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Review 24 line items </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Purchase order PO-7730</DialogTitle> <DialogDescription>Only the list scrolls; the actions stay in view.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={2}> {ITEMS.map((item) => ( <Inline key={item.sku} gap={3} justify="between"> <Text size="sm">{item.name}</Text> <Text size="sm" tone="muted"> {item.sku} </Text> </Inline> ))} </Stack> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => setOpen(false)}>Approve order</Button> </DialogFooter> </DialogContent> </Dialog> <Dialog scroll="viewport"> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Read the terms of sale </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Terms of sale</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={4}> {TERMS.map((term) => ( <Text key={term}>{term}</Text> ))} </Stack> </DialogBody> </DialogContent> </Dialog> </Inline> );}Header, body and footer
DialogHeader (slDialogHeader) lays out the title, the description and the close button; anything else written in it, such as a status badge, sits under the description. DialogBody (slDialogBody) is the row that scrolls, and DialogFooter (slDialogFooter) holds the actions, aligned to the end. Every part is optional: a dialog with no footer draws no footer row.
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';const DETAILS = [ { term: 'Carrier', value: 'UPS Ground' }, { term: 'Tracking number', value: '1Z 999 AA1 01 2345 6784' }, { term: 'Packages', value: '3, 18.4 kg in total' }, { term: 'Estimated delivery', value: 'Thursday, 8 October' },];export default function DialogParts() { const [open, setOpen] = useState(false); return ( <Dialog open={open} onOpenChange={setOpen}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> View shipment </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Shipment SH-4471</DialogTitle> <DialogDescription>Order SO-1182 for Contoso Foods, Seattle.</DialogDescription> <Badge tone="accent">In transit</Badge> <DialogClose /> </DialogHeader> <DialogBody> <DescriptionList> {DETAILS.map((detail) => ( <DescriptionListItem key={detail.term}> <DescriptionListTerm>{detail.term}</DescriptionListTerm> <DescriptionListDescription>{detail.value}</DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Close </Button> <Button>Print label</Button> </DialogFooter> </DialogContent> </Dialog> );}Reading how it closed
Close the dialog from code with a result, through the ref handle in React (dialog.current.close('wait')) or the template reference in Angular (dialog.close('wait')). React’s onOpenChange receives the result on request.result; Angular’s (closed) emits it once the dialog has closed. A close with the ✕, Escape or a press outside carries no result.
import { useRef, useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, type DialogHandle, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';const OUTCOMES: Record<string, string> = { partial: 'Ships the 4 items in stock today.', wait: 'Holds the order until every item is in stock.',};export default function DialogResult() { const dialog = useRef<DialogHandle>(null); const [outcome, setOutcome] = useState<string | null>(null); return ( <Inline align="center" gap={3}> <Dialog ref={dialog} onOpenChange={(open, request) => { if (!open) { setOutcome((request.result && OUTCOMES[request.result]) ?? 'Closed without a choice.'); } }} > <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Ship order SO-1182 </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Two items are out of stock</DialogTitle> <DialogDescription> Aniseed syrup and dried pears are back in stock on 14 October. </DialogDescription> <DialogClose /> </DialogHeader> <DialogFooter> <Button variant="outline" tone="secondary" onClick={() => dialog.current?.close('wait')} > Wait for all items </Button> <Button onClick={() => dialog.current?.close('partial')}>Ship 4 items now</Button> </DialogFooter> </DialogContent> </Dialog> {outcome === null ? null : ( <Text size="sm" tone="muted"> {outcome} </Text> )} </Inline> );}Closing only from the actions
escape="none" and outsidePress="none" keep the dialog open when the reader presses Escape or clicks the backdrop. Use them when a stray key or click must not lose a choice, and leave a visible way out in the footer.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Text } from '@slotted/react/typography';export default function DialogDismiss() { const [open, setOpen] = useState(false); return ( <Dialog open={open} onOpenChange={setOpen} escape="none" outsidePress="none"> <DialogTrigger render={(props) => <Button {...props}>Import products</Button>} /> <DialogContent> <DialogHeader> <DialogTitle>Import 1,240 products</DialogTitle> <DialogDescription> From spring-catalogue.csv into the Northwind price list. </DialogDescription> </DialogHeader> <DialogBody> <Text size="sm"> 38 rows update existing products and 1,202 add new ones. Escape and a press outside the panel leave this dialog open; choose one of the actions. </Text> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel import </Button> <Button onClick={() => setOpen(false)}>Start import</Button> </DialogFooter> </DialogContent> </Dialog> );}Refusing a close with unsaved changes
Every way of closing, from the ✕, Escape, a press outside or the browser’s back gesture, goes through one request: onOpenChange in React and (openChangeRequest) in Angular. Call request.cancel() to keep the dialog open. Here an edited address keeps the dialog open and asks, in an alert dialog over it, whether to discard the change. Edit the address, then press Escape.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';export default function DialogUnsavedChanges() { const [open, setOpen] = useState(false); const [confirming, setConfirming] = useState(false); const [address, setAddress] = useState('Pier 70, Suite 300, Seattle, WA 98121'); const [draft, setDraft] = useState(address); const dirty = draft !== address; const leave = () => { if (dirty) setConfirming(true); else setOpen(false); }; return ( <Inline align="center" gap={3}> <Dialog open={open} onOpenChange={(next, request) => { if (next) { setDraft(address); setOpen(true); } else if (dirty) { request.cancel(); setConfirming(true); } else { setOpen(false); } }} > <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Change delivery address </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Delivery address</DialogTitle> <DialogDescription>Applies to order SO-1182 and to later orders.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Address</FieldLabel> <TextField value={draft} onValueChange={setDraft} /> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={leave}> Cancel </Button> <Button onClick={() => { setAddress(draft); setOpen(false); }} > Save address </Button> </DialogFooter> <AlertDialog open={confirming} onOpenChange={setConfirming} tone="warning"> <DialogContent> <DialogHeader> <AlertDialogIcon /> <DialogTitle>Discard the new address?</DialogTitle> <DialogDescription> The address you typed is not saved. The order keeps the previous one. </DialogDescription> </DialogHeader> <DialogFooter> <AlertDialogCancel render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Keep editing </Button> )} /> <AlertDialogAction onClick={() => setOpen(false)} render={(props) => ( <Button {...props} tone="warning"> Discard changes </Button> )} /> </DialogFooter> </DialogContent> </AlertDialog> </DialogContent> </Dialog> <Text size="sm" tone="muted"> {address} </Text> </Inline> );}Opening from a row
A dialog needs no trigger. Set open from the row’s own button, and keep the row’s data in its own state so the content stays filled while the dialog animates out. Focus returns to the button that opened it.
| Order | Customer | Total | Actions |
|---|---|---|---|
| SO-1182 | Contoso Foods | $1,240.00 | |
| SO-1183 | Fabrikam Grocers | $386.50 | |
| SO-1184 | Tailspin Market | $2,075.25 |
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Table, TableBody, TableCell, TableColumnHeader, TableContent, TableHead, TableRow, TableRowHeader,} from '@slotted/react/table';import { TextField } from '@slotted/react/text-field';import { VisuallyHidden } from '@slotted/react/visually-hidden';const ORDERS = [ { id: 'SO-1182', customer: 'Contoso Foods', total: '$1,240.00', amount: '1240.00', card: '4242' }, { id: 'SO-1183', customer: 'Fabrikam Grocers', total: '$386.50', amount: '386.50', card: '1881' }, { id: 'SO-1184', customer: 'Tailspin Market', total: '$2,075.25', amount: '2075.25', card: '0005', },];type Order = (typeof ORDERS)[number];export default function DialogRowAction() { const [open, setOpen] = useState(false); const [order, setOrder] = useState<Order>(ORDERS[0]!); return ( <> <Table columns={4}> <TableContent> <TableHead> <TableRow> <TableColumnHeader>Order</TableColumnHeader> <TableColumnHeader>Customer</TableColumnHeader> <TableColumnHeader numeric>Total</TableColumnHeader> <TableColumnHeader> <VisuallyHidden>Actions</VisuallyHidden> </TableColumnHeader> </TableRow> </TableHead> <TableBody> {ORDERS.map((row) => ( <TableRow key={row.id} value={row.id}> <TableRowHeader>{row.id}</TableRowHeader> <TableCell>{row.customer}</TableCell> <TableCell numeric>{row.total}</TableCell> <TableCell> <Button aria-label={`Refund ${row.id}`} size="sm" tone="secondary" variant="ghost" onClick={() => { setOrder(row); setOpen(true); }} > Refund </Button> </TableCell> </TableRow> ))} </TableBody> </TableContent> </Table> <Dialog open={open} onOpenChange={setOpen} size="sm"> <DialogContent> <DialogHeader> <DialogTitle>Refund {order.id}</DialogTitle> <DialogDescription> {order.customer} paid {order.total} with the card ending {order.card}. </DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Amount in US dollars</FieldLabel> <TextField key={order.id} inputMode="decimal" defaultValue={order.amount} /> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => setOpen(false)}>Issue refund</Button> </DialogFooter> </DialogContent> </Dialog> </> );}Opening from a menu item
A menu item that opens a dialog sets open from onSelect in React or (select) in Angular. The menu closes as the dialog opens, so name where focus goes afterwards: finalFocus takes the menu trigger, which is where the reader started.
import { useRef, useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Menu, MenuContent, MenuItem, MenuSeparator, MenuTrigger } from '@slotted/react/menu';import { TextField } from '@slotted/react/text-field';export default function DialogMenuAction() { const actions = useRef<HTMLButtonElement>(null); const [open, setOpen] = useState(false); return ( <> <Menu> <MenuTrigger ref={actions} render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Customer actions </Button> )} /> <MenuContent> <MenuItem onSelect={() => setOpen(true)}>Change credit limit…</MenuItem> <MenuItem>Export statement</MenuItem> <MenuSeparator /> <MenuItem tone="danger">Suspend account…</MenuItem> </MenuContent> </Menu> <Dialog open={open} onOpenChange={setOpen} finalFocus={actions} size="sm"> <DialogContent> <DialogHeader> <DialogTitle>Credit limit</DialogTitle> <DialogDescription> Contoso Foods has $18,420.00 outstanding on open invoices. </DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Limit in US dollars</FieldLabel> <TextField inputMode="decimal" defaultValue="25000" /> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={() => setOpen(false)}>Save limit</Button> </DialogFooter> </DialogContent> </Dialog> </> );}Initial focus
When the dialog opens, focus moves to its first focusable element, here the close button. initialFocus names another element, such as a search field; initialFocus="container" focuses the panel itself, for content that is read before it is used. While a modal dialog is open, Tab and Shift+Tab cycle inside it, and Escape closes it and returns focus to the trigger.
import { useRef, useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';const CUSTOMERS = [ 'Contoso Foods', 'Fabrikam Grocers', 'Northwind Traders', 'Tailspin Market', 'Wide World Importers', 'Woodgrove Deli',];export default function DialogInitialFocus() { const search = useRef<HTMLInputElement>(null); const [query, setQuery] = useState(''); const matches = CUSTOMERS.filter((name) => name.toLowerCase().includes(query.toLowerCase())); return ( <Dialog initialFocus={search} onOpenChange={(open) => open && setQuery('')}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Find a customer </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Find a customer</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={4}> <TextField ref={search} aria-label="Customer name" placeholder="Search by name" type="search" value={query} onValueChange={setQuery} /> <Stack gap={2}> {matches.map((name) => ( <Text key={name} size="sm"> {name} </Text> ))} </Stack> </Stack> </DialogBody> </DialogContent> </Dialog> );}A dialog over a dialog
A dialog opened from inside another stacks above it. Escape and a press outside close only the top one, and focus returns to the control in the dialog below.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Dialog, DialogBody, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from '@slotted/react/select';const CARRIERS = [ { value: 'ups', label: 'UPS Ground' }, { value: 'fedex', label: 'FedEx Ground' }, { value: 'usps', label: 'USPS Priority Mail' },];const labelOf = (value: string) => CARRIERS.find((carrier) => carrier.value === value)?.label;export default function DialogNested() { const [carrier, setCarrier] = useState('ups'); const [changing, setChanging] = useState(false); const [draft, setDraft] = useState(carrier); return ( <Dialog> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Open order SO-1182 </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Order SO-1182</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <DescriptionList> <DescriptionListItem> <DescriptionListTerm>Customer</DescriptionListTerm> <DescriptionListDescription>Contoso Foods</DescriptionListDescription> </DescriptionListItem> <DescriptionListItem> <DescriptionListTerm>Carrier</DescriptionListTerm> <DescriptionListDescription>{labelOf(carrier)}</DescriptionListDescription> </DescriptionListItem> </DescriptionList> </DialogBody> <DialogFooter> <Dialog open={changing} onOpenChange={(next) => { if (next) setDraft(carrier); setChanging(next); }} size="sm" > <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Change carrier </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Change carrier</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Field> <FieldLabel>Carrier</FieldLabel> <Select items={CARRIERS} value={draft} onValueChange={(next) => { if (typeof next === 'string') setDraft(next); }} > <SelectTrigger> <SelectValue /> </SelectTrigger> <SelectContent> {CARRIERS.map((option) => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setChanging(false)}> Cancel </Button> <Button onClick={() => { setCarrier(draft); setChanging(false); }} > Use carrier </Button> </DialogFooter> </DialogContent> </Dialog> </DialogFooter> </DialogContent> </Dialog> );}A form in a dialog
Put the form in the body and point the footer’s submit button at it with the form attribute, so the actions stay in the footer row. Enter in a field submits it. Validate on submit, show each error in the field, and close the dialog only when the data is valid. Submit the empty form to see the errors.
import { useState, type SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldError, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';function nameError(value: string): string { return value.trim() === '' ? 'Enter the contact’s full name.' : '';}function emailError(value: string): string { if (value.trim() === '') return 'Enter the address the contact reads.'; if (!/^\S+@\S+\.\S+$/.test(value)) return 'Enter an address like ana@contoso.com.'; return '';}export default function DialogForm() { const [open, setOpen] = useState(false); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [submitted, setSubmitted] = useState(false); const [added, setAdded] = useState<string | null>(null); const errors = submitted ? { name: nameError(name), email: emailError(email) } : null; const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); setSubmitted(true); if (nameError(name) !== '' || emailError(email) !== '') return; setAdded(`${name.trim()} was added to Contoso Foods.`); setOpen(false); }; return ( <Inline align="center" gap={3}> <Dialog open={open} onOpenChange={(next) => { if (next) { setName(''); setEmail(''); setSubmitted(false); } setOpen(next); }} > <DialogTrigger render={(props) => <Button {...props}>Add contact</Button>} /> <DialogContent> <DialogHeader> <DialogTitle>New contact</DialogTitle> <DialogDescription>Contoso Foods, Seattle.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <form id="new-contact" noValidate onSubmit={submit}> <Stack gap={4}> <Field required invalid={errors?.name ? true : undefined}> <FieldLabel>Full name</FieldLabel> <TextField autoComplete="name" value={name} onValueChange={setName} /> <FieldError live="polite" reserve> {errors?.name} </FieldError> </Field> <Field required invalid={errors?.email ? true : undefined}> <FieldLabel>Email</FieldLabel> <TextField autoComplete="email" type="email" value={email} onValueChange={setEmail} /> <FieldError live="polite" reserve> {errors?.email} </FieldError> </Field> </Stack> </form> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button type="submit" form="new-contact"> Add contact </Button> </DialogFooter> </DialogContent> </Dialog> {added === null ? null : ( <Text role="status" size="sm" tone="muted"> {added} </Text> )} </Inline> );}Saving
While a save is in progress, show it on the button that started it with loading, disable the other actions, and refuse every close request so the result is not lost. Close the dialog when the save completes.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';export default function DialogAsyncSubmit() { const [open, setOpen] = useState(false); const [saving, setSaving] = useState(false); const [sent, setSent] = useState(false); const refund = () => { setSaving(true); setTimeout(() => { setSaving(false); setSent(true); setOpen(false); }, 1500); }; return ( <Inline align="center" gap={3}> <Dialog open={open} onOpenChange={(next, request) => { if (!next && saving) return request.cancel(); if (next) setSent(false); setOpen(next); }} > <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Refund order SO-1182 </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Refund $1,240.00</DialogTitle> <DialogDescription>To the card ending 4242, for order SO-1182.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Text size="sm"> The payment provider takes a moment to confirm. The dialog stays open until it does. </Text> </DialogBody> <DialogFooter> <Button disabled={saving} variant="ghost" tone="secondary" onClick={() => setOpen(false)} > Cancel </Button> <Button loading={saving} messages={{ loading: 'Issuing refund' }} onClick={refund}> Issue refund </Button> </DialogFooter> </DialogContent> </Dialog> {sent ? ( <Text role="status" size="sm" tone="muted"> Refund issued. </Text> ) : null} </Inline> );}Loading content
loading marks the body as busy with aria-busy and keeps a minimum height, while the header, the ✕ and Escape stay available. Fill the body with skeletons in the shape of the content that is coming, so nothing moves when it arrives.
import { useEffect, useState } from 'react';import { Button } from '@slotted/react/button';import { DescriptionList, DescriptionListDescription, DescriptionListItem, DescriptionListTerm,} from '@slotted/react/description-list';import { Dialog, DialogBody, DialogClose, DialogContent, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Skeleton, SkeletonRegion } from '@slotted/react/skeleton';interface Invoice { customer: string; issued: string; due: string; amount: string;}const FIELDS: { key: keyof Invoice; term: string; width: string }[] = [ { key: 'customer', term: 'Customer', width: '9rem' }, { key: 'issued', term: 'Issued', width: '6rem' }, { key: 'due', term: 'Due', width: '6rem' }, { key: 'amount', term: 'Amount', width: '5rem' },];export default function DialogLoading() { const [open, setOpen] = useState(false); const [invoice, setInvoice] = useState<Invoice | null>(null); useEffect(() => { if (!open) return; setInvoice(null); const timer = setTimeout( () => setInvoice({ customer: 'Northwind Traders', issued: '12 August 2026', due: '11 September 2026', amount: '$1,240.00', }), 1200, ); return () => clearTimeout(timer); }, [open]); return ( <Dialog open={open} onOpenChange={setOpen} loading={invoice === null}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> View invoice INV-2041 </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Invoice INV-2041</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <SkeletonRegion delay={200} loading={invoice === null} messages={{ label: 'Loading invoice' }} > <DescriptionList> {FIELDS.map((field) => ( <DescriptionListItem key={field.key}> <DescriptionListTerm>{field.term}</DescriptionListTerm> <DescriptionListDescription> {invoice === null ? <Skeleton inlineSize={field.width} /> : invoice[field.key]} </DescriptionListDescription> </DescriptionListItem> ))} </DescriptionList> </SkeletonRegion> </DialogBody> </DialogContent> </Dialog> );}Confirming a destructive action
AlertDialog (sl-alert-dialog) is the dialog for a confirmation. It is always modal, a press outside never closes it, and focus starts on AlertDialogCancel (slAlertDialogCancel), the safe answer. It requires a description, and has no ✕: the reader answers with the cancel or the action. Label both buttons with what they do.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';export default function DialogDestructive() { const [deleted, setDeleted] = useState(false); return ( <Inline align="center" gap={3}> <AlertDialog> <DialogTrigger render={(props) => ( <Button {...props} tone="danger" variant="outline"> Delete price list </Button> )} /> <DialogContent> <DialogHeader> <AlertDialogIcon /> <DialogTitle>Delete the 2026 wholesale price list?</DialogTitle> <DialogDescription> The 412 prices in it are removed, and 9 customers on this list move to retail prices. This cannot be undone. </DialogDescription> </DialogHeader> <DialogFooter> <AlertDialogCancel render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Keep price list </Button> )} /> <AlertDialogAction onClick={() => setDeleted(true)} render={(props) => ( <Button {...props} tone="danger"> Delete price list </Button> )} /> </DialogFooter> </DialogContent> </AlertDialog> {deleted ? ( <Text role="status" size="sm" tone="muted"> The 2026 wholesale price list was deleted. </Text> ) : null} </Inline> );}Alert tones
tone sets the alert dialog’s mark and its color: danger (the default) for an action that destroys data, warning for one with consequences, accent for an ordinary confirmation, and success and secondary beside them. Give the action button the same tone.
import { Button } from '@slotted/react/button';import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, type DialogTone, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';const CONFIRMATIONS: { tone: DialogTone; trigger: string; title: string; description: string; action: string;}[] = [ { tone: 'accent', trigger: 'Send invoices', title: 'Send 214 invoices?', description: 'Each customer receives the September invoice by email within the hour.', action: 'Send invoices', }, { tone: 'warning', trigger: 'Publish prices', title: 'Publish the new prices?', description: 'Open quotes keep their prices; new orders use the new ones from now on.', action: 'Publish prices', }, { tone: 'success', trigger: 'Close September', title: 'Close the books for September?', description: 'All 1,180 entries reconcile. Entries dated September can no longer be edited.', action: 'Close September', },];export default function DialogAlertTones() { return ( <Inline gap={2}> {CONFIRMATIONS.map((confirmation) => ( <AlertDialog key={confirmation.tone} tone={confirmation.tone}> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> {confirmation.trigger} </Button> )} /> <DialogContent> <DialogHeader> <AlertDialogIcon /> <DialogTitle>{confirmation.title}</DialogTitle> <DialogDescription>{confirmation.description}</DialogDescription> </DialogHeader> <DialogFooter> <AlertDialogCancel render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Not now </Button> )} /> <AlertDialogAction render={(props) => ( <Button {...props} tone={confirmation.tone}> {confirmation.action} </Button> )} /> </DialogFooter> </DialogContent> </AlertDialog> ))} </Inline> );}Non-modal
modal={false} ([modal]="false") leaves the page behind interactive: no scrim is drawn, the pointer and the wheel reach the page, nothing is made inert, the page scroll is not locked, focus can leave the panel, and the panel has no aria-modal. Use it for reference content the reader works beside, with outsidePress="none" so working on the page does not close it.
import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const STEPS = [ 'Pick the 6 lines on the pick list from aisles 4 and 9.', 'Pack the olive oil upright, with dividers.', 'Print the UPS label and attach it to the top face.',];export default function DialogNonModal() { return ( <Dialog modal={false} outsidePress="none" placement="top" size="sm"> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Show packing steps </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Packing steps</DialogTitle> <DialogDescription> Order SO-1182. The page stays usable behind this panel. </DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={2}> {STEPS.map((step, index) => ( <Text key={step} size="sm"> {index + 1}. {step} </Text> ))} </Stack> </DialogBody> </DialogContent> </Dialog> );}Full screen
By default, a dialog fills the whole layer when the layer is narrower than 480 pixels, without margins or rounded corners. fullScreen="always" does so at every width and fullScreen="never" keeps the margins. fullscreenToggle adds a button to the header that lets the reader expand the panel and restore it.
import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const STOPS = [ { time: '08:10', place: 'Contoso Foods, 1200 Pike St' }, { time: '08:55', place: 'Fabrikam Grocers, 410 Broadway E' }, { time: '09:40', place: 'Tailspin Market, 3300 Fremont Ave N' }, { time: '10:30', place: 'Woodgrove Deli, 85 Pine St' }, { time: '11:15', place: 'Wide World Importers, 2201 1st Ave S' },];export default function DialogFullScreen() { return ( <Dialog fullscreenToggle size="lg"> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Open route plan </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Route 14, Tuesday 6 October</DialogTitle> <DialogDescription>5 stops, 38 km, driver Ana Souza.</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={3}> {STOPS.map((stop) => ( <Inline key={stop.time} gap={4}> <Text size="sm" tone="muted"> {stop.time} </Text> <Text size="sm">{stop.place}</Text> </Inline> ))} </Stack> </DialogBody> </DialogContent> </Dialog> );}Defaults for a section
DialogDefaultsProvider in React and provideDialogDefaults in Angular set size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress and back once for every dialog under them. A value set on one dialog still wins.
import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDefaultsProvider, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';export default function DialogDefaults() { return ( <DialogDefaultsProvider placement="top" size="lg"> <Inline gap={2}> <Dialog> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Purchase order PO-7730 </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Purchase order PO-7730</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Text size="sm">Large and at the top, from the provider.</Text> </DialogBody> </DialogContent> </Dialog> <Dialog size="sm"> <DialogTrigger render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Rename supplier </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle>Rename supplier</DialogTitle> <DialogClose /> </DialogHeader> <DialogBody> <Text size="sm">At the top from the provider, and small because it says so.</Text> </DialogBody> </DialogContent> </Dialog> </Inline> </DialogDefaultsProvider> );}Cancelling an order
An alert dialog can hold a field. Here the reason is required, so the action stays disabled until one is chosen; the description states what the cancellation does before the reader commits.
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from '@slotted/react/select';import { Text } from '@slotted/react/typography';const REASONS = [ { value: 'customer', label: 'The customer asked to cancel' }, { value: 'stock', label: 'Items are out of stock' }, { value: 'payment', label: 'The payment was flagged' }, { value: 'duplicate', label: 'Duplicate order' },];export default function DialogCancelOrder() { const [cancelled, setCancelled] = useState(false); const [reason, setReason] = useState<string | null>(null); return ( <Inline align="center" gap={3}> <Text weight="medium">Order SO-1182</Text> <Badge tone={cancelled ? 'danger' : 'accent'}>{cancelled ? 'Cancelled' : 'Processing'}</Badge> <AlertDialog onOpenChange={(open) => open && setReason(null)}> <DialogTrigger render={(props) => ( <Button {...props} disabled={cancelled} focusableWhenDisabled size="sm" tone="danger" variant="outline" > Cancel order </Button> )} /> <DialogContent> <DialogHeader> <AlertDialogIcon /> <DialogTitle>Cancel order SO-1182?</DialogTitle> <DialogDescription> Contoso Foods is refunded $1,240.00 and the 6 items go back to stock. The order cannot be reopened. </DialogDescription> </DialogHeader> <DialogBody> <Field required> <FieldLabel>Reason</FieldLabel> <Select items={REASONS} value={reason} onValueChange={(next) => setReason(typeof next === 'string' ? next : null)} > <SelectTrigger> <SelectValue placeholder="Choose a reason" /> </SelectTrigger> <SelectContent> {REASONS.map((option) => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> </DialogBody> <DialogFooter> <AlertDialogCancel render={(props) => ( <Button {...props} tone="secondary" variant="outline"> Keep order </Button> )} /> <AlertDialogAction onClick={() => setCancelled(true)} render={(props) => ( <Button {...props} disabled={reason === null} tone="danger"> Cancel order </Button> )} /> </DialogFooter> </DialogContent> </AlertDialog> </Inline> );}Creating a shipment from an order
A larger dialog composes a form: a select with descriptions, a validated field, a checkbox and a submit that saves for a moment. The close requests are refused while the shipment is being created.
import { useState, type SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Checkbox } from '@slotted/react/checkbox';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldDescription, FieldError, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from '@slotted/react/select';import { Stack } from '@slotted/react/stack';import { TextField } from '@slotted/react/text-field';import { Text } from '@slotted/react/typography';const CARRIERS = [ { value: 'ups', label: 'UPS Ground', description: '3–5 business days' }, { value: 'fedex', label: 'FedEx 2Day', description: '2 business days' }, { value: 'usps', label: 'USPS Priority Mail', description: '1–3 business days' },];function weightError(value: string): string { if (value.trim() === '') return 'Enter the total weight of the packages.'; const weight = Number(value); if (!Number.isFinite(weight) || weight <= 0) return 'Enter a weight above 0, such as 18.4.'; return '';}export default function DialogCreateShipment() { const [open, setOpen] = useState(false); const [carrier, setCarrier] = useState('ups'); const [weight, setWeight] = useState(''); const [submitted, setSubmitted] = useState(false); const [saving, setSaving] = useState(false); const [created, setCreated] = useState<string | null>(null); const error = submitted ? weightError(weight) : ''; const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); setSubmitted(true); if (weightError(weight) !== '') return; setSaving(true); setTimeout(() => { const label = CARRIERS.find((option) => option.value === carrier)?.label; setSaving(false); setCreated(`Shipment SH-4472 created with ${label}.`); setOpen(false); }, 1200); }; return ( <Inline align="center" gap={3}> <Dialog open={open} onOpenChange={(next, request) => { if (!next && saving) return request.cancel(); if (next) { setWeight(''); setSubmitted(false); } setOpen(next); }} size="lg" > <DialogTrigger render={(props) => <Button {...props}>Create shipment</Button>} /> <DialogContent> <DialogHeader> <DialogTitle>Create a shipment</DialogTitle> <DialogDescription> Order SO-1182 for Contoso Foods: 6 items to 1200 Pike St, Seattle. </DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <form id="create-shipment" noValidate onSubmit={submit}> <Stack gap={5}> <Field> <FieldLabel>Carrier</FieldLabel> <Select items={CARRIERS} name="carrier" value={carrier} onValueChange={(next) => { if (typeof next === 'string') setCarrier(next); }} > <SelectTrigger> <SelectValue /> </SelectTrigger> <SelectContent> {CARRIERS.map((option) => ( <SelectItem key={option.value} description={option.description} value={option.value} > {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> <Field required invalid={error !== '' ? true : undefined}> <FieldLabel>Weight in kilograms</FieldLabel> <FieldDescription> All packages together, as weighed at the dock. </FieldDescription> <TextField inputMode="decimal" name="weight" value={weight} onValueChange={setWeight} /> <FieldError live="polite" reserve> {error} </FieldError> </Field> <Checkbox defaultChecked name="notify"> Email the tracking number to the customer </Checkbox> </Stack> </form> </DialogBody> <DialogFooter> <Button disabled={saving} variant="ghost" tone="secondary" onClick={() => setOpen(false)} > Cancel </Button> <Button form="create-shipment" loading={saving} messages={{ loading: 'Creating shipment' }} type="submit" > Create shipment </Button> </DialogFooter> </DialogContent> </Dialog> {created === null ? null : ( <Text role="status" size="sm" tone="muted"> {created} </Text> )} </Inline> );}Editing selected rows
The selection in a table decides what the dialog edits. The selected ids are copied when the dialog opens, so the title, the description and the update name the same rows, and the selection is cleared after the update. Select two orders, then edit them.
| Order | Customer | Status | Ships from | |
|---|---|---|---|---|
| SO-1182 | Contoso Foods | Processing | Reno, NV | |
| SO-1183 | Fabrikam Grocers | Processing | Columbus, OH | |
| SO-1184 | Tailspin Market | On hold | Reno, NV | |
| SO-1185 | Woodgrove Deli | Processing | Savannah, GA |
import { useState } from 'react';import { Badge } from '@slotted/react/badge';import { Button } from '@slotted/react/button';import { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from '@slotted/react/dialog';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue,} from '@slotted/react/select';import { Stack } from '@slotted/react/stack';import { Table, TableBody, TableCell, TableColumnHeader, TableContent, TableHead, TableRow, TableRowHeader, TableSelect, TableSelectAll,} from '@slotted/react/table';import { Text } from '@slotted/react/typography';const STATUSES = [ { value: 'processing', label: 'Processing', tone: 'accent' }, { value: 'hold', label: 'On hold', tone: 'warning' }, { value: 'ready', label: 'Ready to ship', tone: 'success' },] as const;const WAREHOUSES = [ { value: 'RNO', label: 'Reno, NV' }, { value: 'CMH', label: 'Columbus, OH' }, { value: 'SAV', label: 'Savannah, GA' },];type Status = (typeof STATUSES)[number]['value'];const INITIAL: { id: string; customer: string; status: Status; warehouse: string }[] = [ { id: 'SO-1182', customer: 'Contoso Foods', status: 'processing', warehouse: 'RNO' }, { id: 'SO-1183', customer: 'Fabrikam Grocers', status: 'processing', warehouse: 'CMH' }, { id: 'SO-1184', customer: 'Tailspin Market', status: 'hold', warehouse: 'RNO' }, { id: 'SO-1185', customer: 'Woodgrove Deli', status: 'processing', warehouse: 'SAV' },];const statusOf = (value: Status) => STATUSES.find((status) => status.value === value)!;const warehouseOf = (value: string) => WAREHOUSES.find((option) => option.value === value)?.label;export default function DialogBulkEdit() { const [orders, setOrders] = useState(INITIAL); const [chosen, setChosen] = useState<readonly string[]>([]); const [editing, setEditing] = useState<readonly string[]>([]); const [open, setOpen] = useState(false); const [status, setStatus] = useState<Status>('ready'); const [warehouse, setWarehouse] = useState('RNO'); const count = chosen.length; const noun = editing.length === 1 ? 'order' : 'orders'; const apply = () => { setOrders((rows) => rows.map((row) => (editing.includes(row.id) ? { ...row, status, warehouse } : row)), ); setChosen([]); setOpen(false); }; return ( <Stack gap={3}> <Inline align="center" gap={3}> <Text size="sm" tone="muted"> {count === 0 ? 'Select orders to edit them together.' : `${count} selected`} </Text> <Dialog open={open} onOpenChange={(next) => { if (next) setEditing(chosen); setOpen(next); }} > <DialogTrigger render={(props) => ( <Button {...props} disabled={count === 0} focusableWhenDisabled size="sm" tone="secondary" variant="outline" > Edit selected </Button> )} /> <DialogContent> <DialogHeader> <DialogTitle> Edit {editing.length} {noun} </DialogTitle> <DialogDescription>{editing.join(', ')}</DialogDescription> <DialogClose /> </DialogHeader> <DialogBody> <Stack gap={4}> <Field> <FieldLabel>Status</FieldLabel> <Select items={[...STATUSES]} value={status} onValueChange={(next) => { if (typeof next === 'string') setStatus(next as Status); }} > <SelectTrigger> <SelectValue /> </SelectTrigger> <SelectContent> {STATUSES.map((option) => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> <Field> <FieldLabel>Ships from</FieldLabel> <Select items={WAREHOUSES} value={warehouse} onValueChange={(next) => { if (typeof next === 'string') setWarehouse(next); }} > <SelectTrigger> <SelectValue /> </SelectTrigger> <SelectContent> {WAREHOUSES.map((option) => ( <SelectItem key={option.value} value={option.value}> {option.label} </SelectItem> ))} </SelectContent> </Select> </Field> </Stack> </DialogBody> <DialogFooter> <Button variant="ghost" tone="secondary" onClick={() => setOpen(false)}> Cancel </Button> <Button onClick={apply}> Update {editing.length} {noun} </Button> </DialogFooter> </DialogContent> </Dialog> </Inline> <Table columns={5} selectionMode="multiple" value={chosen} onValueChange={setChosen}> <TableContent> <TableHead> <TableRow> <TableSelectAll /> <TableColumnHeader>Order</TableColumnHeader> <TableColumnHeader>Customer</TableColumnHeader> <TableColumnHeader>Status</TableColumnHeader> <TableColumnHeader>Ships from</TableColumnHeader> </TableRow> </TableHead> <TableBody> {orders.map((row) => ( <TableRow key={row.id} value={row.id}> <TableSelect /> <TableRowHeader>{row.id}</TableRowHeader> <TableCell>{row.customer}</TableCell> <TableCell> <Badge tone={statusOf(row.status).tone}>{statusOf(row.status).label}</Badge> </TableCell> <TableCell>{warehouseOf(row.warehouse)}</TableCell> </TableRow> ))} </TableBody> </TableContent> </Table> </Stack> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| Tab | moves to the next tabbable element inside the layer, and wraps from the last to the first while modal | the next tabbable element inside the layer |
| Shift+Tab | moves to the previous tabbable element inside the layer, and wraps from the first to the last while modal | the previous tabbable element inside the layer |
| Escape | asks the topmost layer to close, carrying the reason escape; a layer that refuses stops the request reaching the layer beneath it, so one Escape never closes two | returns to the element that held it when the layer opened |
Dialog
- Dialog follows the WAI-ARIA dialog (modal) pattern. While a modal dialog is open, Tab and Shift+Tab move through the focusable elements inside it and wrap from the last to the first and back. Escape closes the topmost dialog only; a dialog that refuses the close keeps the Escape from reaching the dialog beneath it.
- The panel carries role="dialog", aria-labelledby pointing at the title and aria-describedby pointing at the description, each only while that part is rendered. An aria-label of your own on DialogContent replaces aria-labelledby.
- aria-modal="true" is written only while the dialog is modal. A modal dialog makes everything outside it inert, which removes the page from the accessibility tree and from the pointer, and locks the page scroll. modal={false} does none of this and writes no aria-modal.
- When the dialog opens, focus moves to its first focusable element, to the element initialFocus names, or to the panel itself with initialFocus="container", for content that is read before it is used. When it closes, focus returns to the element that had it when the dialog opened, or to the element finalFocus names. If that element has left the document, focus goes to its nearest ancestor still in the document.
- Containment, inertness and Escape are implemented in JavaScript rather than with the native dialog element, so every overlay of the library shares one stacking order: a select opened inside a dialog paints above it. Without JavaScript, there is no dialog.
- The close button’s target is at least 24 by 24 pixels, and its mark is drawn from a glyph, not a character.
- The panel has a border as well as a shadow, so its edge stays visible under forced colors, where shadows are removed and the scrim becomes opaque.
AlertDialog
- AlertDialog follows the WAI-ARIA alert dialog pattern: the modal dialog pattern with role="alertdialog" and a required description. The keyboard is the same: Tab and Shift+Tab wrap inside the panel, and Escape closes it.
- aria-describedby is required. AlertDialog throws an error when no DialogDescription is rendered, so a confirmation is never announced without the sentence that says what it does.
- Focus starts on AlertDialogCancel, the least destructive answer, as the pattern advises for a step that cannot be undone easily.
- A press outside never closes an alert dialog, and it is always modal. Escape closes it, which answers with the cancel; set escape="none" when cancelling is not safe either.
- There is no close part: the reader answers with the cancel or the action. Rendering DialogClose inside AlertDialog throws an error.
- The tone is carried by the icon’s shape as well as by its color, so it survives forced colors and readers who cannot tell the colors apart.
API
Dialog
Props
openboolean- On Dialog, AlertDialogWhether the dialog is open. Passing it makes the state controlled: the dialog asks through onOpenChange and waits for the new value.
defaultOpenboolean- On Dialog, AlertDialogWhether an uncontrolled dialog starts open. Read once.
size'sm' | 'md' | 'lg' | 'xl' | 'full'Defaultmd- On Dialog, DialogDefaultsProviderThe maximum width of the panel: 32rem, the form measure plus the panel padding (43rem by default), 48rem, 56rem, or the whole layer less its padding. For another width, set --slotted-dialog-measure, or --slotted-dialog-measure-sm, -md, -lg or -xl for one step.
placement'center' | 'top'Defaultcenter- On Dialog, AlertDialog, DialogDefaultsProviderWhere the panel sits in the layer. Use top for content that grows while the reader types, so the panel does not move with each new line.
scroll'content' | 'viewport'Defaultcontent- On Dialog, AlertDialog, DialogDefaultsProviderWhat scrolls when the content is long. content keeps the panel inside the layer and scrolls the body, so the actions stay on screen; viewport lets the panel grow and scrolls the layer. With content, the layer still scrolls when the header and footer alone are taller than it.
mount'active' | 'lazy' | 'eager'Defaultactive- On Dialog, AlertDialog, DialogDefaultsProviderWhen the layer is in the document. active renders it while open and removes it after the closing animation, lazy renders it on the first open and keeps it, eager renders it from the start and hides it with content-visibility and inert while closed.
escape'close' | 'none'Defaultclose- On Dialog, AlertDialog, DialogDefaultsProviderWhether Escape asks the dialog to close. Escape reaches the topmost dialog only.
loadingbooleanDefaultfalse- On Dialog, AlertDialogMarks the body with aria-busy and gives it a minimum height while the content is on its way. The header, the close button and Escape stay available.
messagesPartial<DialogMessages>- On Dialog, AlertDialogReplaces words of the language in force, key by key: the accessible names of the close and full-screen buttons (close, fullScreen). An aria-label on DialogClose takes precedence.
initialFocus'first' | 'container' | 'cancel' | RefObject | falseDefaultfirst- Where focus goes when the dialog opens: the first focusable element, the panel itself (container), the cancel part, the element of a ref, or nowhere (false). Use container for content that is read before it is used, such as a list or a table.
finalFocusRefObject | false- On Dialog, AlertDialogWhere focus goes when the dialog closes. Unset, focus returns to the element that had it when the dialog opened, usually the trigger. false leaves focus where it is.
valuestring- On DialogClose, AlertDialogCancel, AlertDialogActionThe result this button closes the dialog with, read from request.result in onOpenChange. AlertDialogCancel defaults to "cancel" and AlertDialogAction to "confirm".
modalbooleanDefaulttrue- On Dialog, DialogDefaultsProviderWhether the page behind is inert, its scroll locked and focus kept inside the panel. false does none of this, paints no scrim, lets the pointer reach the page and writes no aria-modal.
outsidePress'close' | 'none'Defaultclose- On Dialog, DialogDefaultsProviderWhether a press outside the panel asks the dialog to close. AlertDialog fixes it at none.
back'close' | 'none'Defaultclose- On Dialog, DialogDefaultsProviderWhether the browser’s way back, a back button or a phone’s back gesture, closes a modal dialog instead of leaving the page. Each open modal dialog holds one close watcher where the browser has CloseWatcher, and adds one history entry elsewhere; the close request carries the reason back. A dialog opened without a press shares the way back with the layer opened before it.
surface'panel' | 'plain'Defaultpanel- On Dialog, DialogDefaultsProviderWhether Dialog paints the panel. plain removes the background, border, radius, shadow, rows and padding, and keeps the portal, the scrim, focus handling and the dismissal policy, for a panel of your own such as a Card or an image viewer. A plain panel does not keep its footer on screen for a long body.
fullScreen'never' | 'narrow' | 'always'Defaultnarrow- On Dialog, DialogDefaultsProviderWhen the panel fills the whole layer, without margins or radius. narrow does so while the layer is narrower than 480 pixels, measured with a container query on the layer.
fullscreenTogglebooleanDefaultfalse- Adds a button to the header that expands the panel to the whole layer and restores it, for content the reader wants more room for.
fullscreenboolean- Whether the panel is expanded by the toggle. Passing it makes the state controlled, with onFullscreenChange.
defaultFullscreenbooleanDefaultfalse- Whether an uncontrolled panel opens expanded. Read once.
Events
| Name | Payload | When |
|---|---|---|
onOpenChange | (open: boolean, request: DialogChangeRequest) | Before the dialog opens or closes, whatever caused it. The request carries the new value, the previous value, the reason (pointer, keyboard, dismiss, escape, outsidePress, back, submit or programmatic), the result of the close, the originating event, and cancel(), which keeps the dialog as it is. One handler therefore guards the ✕, Escape, a press outside, the way back and the ref handle together. |
onOpenChangeComplete | (open: boolean) | After the entrance or the exit has ended: true once the layer is settled open, false once it has left — the moment an application that renders the layer conditionally removes it, so the exit runs. A layer mounted open enters from its closed style, as one opened later does. |
onFullscreenChange | (fullscreen: boolean, request: DialogFullscreenRequest) | Before the panel expands to the whole layer or is restored. The request carries the new value, the previous value, the reason (pointer, keyboard or programmatic), the originating event, and cancel(), which keeps the panel as it is. |
onClick, onKeyDown and the other native events, on every part | the element’s own event | Whenever the element fires them. Your handler runs before the dialog’s own, and calling preventDefault() in it cancels the dialog’s behavior, such as opening on a trigger press or closing on a close press. |
Composition
render(props) => ReactNode- On every partReplaces the element a part renders and passes it every attribute the part writes. Use it to make the trigger, the cancel and the action a Button.
refRef<DialogHandle> on Dialog, Ref<HTMLElement> on every part- On Dialog, AlertDialog, every partOn a part, the element. On Dialog and AlertDialog, a handle with open(), close(result), focus() and content, the panel element once it is rendered.
--slotted-dialog-measurelengthDefault from size- On the root partThe maximum width of the panel, for a width the five sizes do not hold, such as a two-column form at 46rem. Set it with a style attribute on one dialog, with a rule for a region, or once in the theme. It takes precedence over size, and a step token takes precedence over it.
--slotted-dialog-measure-sm, -md, -lg, -xllengthDefault from size- On the root partThe maximum width of one size step, read before --slotted-dialog-measure, so a theme widens one step and keeps the others.
containerElement | null- On Dialog, AlertDialogThe element this dialog is rendered into, instead of the shared portal root. To change the portal root for the whole document, call setPortalContainer from @slotted/core/portal.
useDialog()() => DialogContextValue- On inside Dialog or AlertDialogWhat the parts read: the open state, the ids, the resolved axes and close(reason, result). It throws outside Dialog and AlertDialog.
DialogDefaultsProvider{ size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress, back }- On a subtreeSets these ten values once for every dialog under it. A value set on one dialog takes precedence.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, in a portal | Yes | The layer, fixed over the viewport. It carries data-ui="dialog", one attribute per axis, data-open and data-loading, and a z-index of --slotted-z-index-overlay plus the depth of the layer stack, so a dialog opened over another sits above it. It is also the container that fullScreen="narrow" measures, so full screen follows the width of the layer rather than the width of the window. |
trigger | button, or the element render returns | No | The control that opens the dialog. It stays where it is written while the layer is rendered in a portal, and carries aria-haspopup, aria-expanded and aria-controls. A press on it does not count as a press outside the dialog. Rendered as a Button, the element keeps the button’s data-part="root". |
backdrop | div | Yes | The scrim behind the panel, painted from --slotted-scrim. It does not scroll. A non-modal dialog does not paint it and lets the pointer through to the page. |
viewport | div | Yes | The box that positions the panel and, with scroll="viewport", the box that scrolls. A panel taller than the layer aligns to the top edge, so its title stays on screen. |
content | div | Yes | The panel. It carries role="dialog" and, while modal, aria-modal="true". It is a grid of three rows, header, body and footer, and only the body row shrinks, so the actions stay on screen when the body is long. It draws no padding: DialogHeader, DialogBody and DialogFooter carry the panel inset. A layout that skips them reads --slotted-dialog-inset-inline and --slotted-dialog-inset-block, which the panel states, and a theme sets the inset with --slotted-dialog-padding-inline and --slotted-dialog-padding-block. |
header | header, or the element render returns | No | Three columns: the mark, the words and the corner buttons. A title that wraps makes the row taller and never pushes the close button off the line. Any other content written in the header, such as a badge, is placed in the words column under the description. |
title | h2, or the element render returns | No | The visible name of the dialog. The panel points aria-labelledby at it only while it is rendered. |
description | p, or the element render returns | No | The sentence that says what the dialog is for. The panel points aria-describedby at it only while it is rendered. It is optional in Dialog and required in AlertDialog. |
body | div, or the element render returns | No | The row that scrolls. It carries aria-busy while loading is set. Scrolling it to the end does not scroll the page behind a non-modal dialog. |
footer | footer, or the element render returns | No | The actions: a row aligned to the end that wraps when the buttons do not fit, on the sunken surface. Each row of the panel draws the rule above itself, so a panel without a body draws one rule, not two. |
close | button | No | The ✕ button. Its target is at least 24 by 24 pixels. It closes the dialog with the reason dismiss, carrying its value as the result. |
fullscreen | button | No | The button that expands the panel to the whole layer and restores it, rendered by DialogHeader when fullscreenToggle is set. It sits before the close button, carries aria-pressed, and its mark shows what the next press does. |
AlertDialog
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogIcon, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@slotted/react';Props
openboolean- On Dialog, AlertDialogWhether the dialog is open. Passing it makes the state controlled: the dialog asks through onOpenChange and waits for the new value.
defaultOpenboolean- On Dialog, AlertDialogWhether an uncontrolled dialog starts open. Read once.
size'sm' | 'md' | 'lg' | 'xl' | 'full'Defaultsm- The maximum width of the panel. AlertDialog defaults to sm, 32rem.
placement'center' | 'top'Defaultcenter- On Dialog, AlertDialog, DialogDefaultsProviderWhere the panel sits in the layer. Use top for content that grows while the reader types, so the panel does not move with each new line.
scroll'content' | 'viewport'Defaultcontent- On Dialog, AlertDialog, DialogDefaultsProviderWhat scrolls when the content is long. content keeps the panel inside the layer and scrolls the body, so the actions stay on screen; viewport lets the panel grow and scrolls the layer. With content, the layer still scrolls when the header and footer alone are taller than it.
mount'active' | 'lazy' | 'eager'Defaultactive- On Dialog, AlertDialog, DialogDefaultsProviderWhen the layer is in the document. active renders it while open and removes it after the closing animation, lazy renders it on the first open and keeps it, eager renders it from the start and hides it with content-visibility and inert while closed.
escape'close' | 'none'Defaultclose- On Dialog, AlertDialog, DialogDefaultsProviderWhether Escape asks the dialog to close. Escape reaches the topmost dialog only.
loadingbooleanDefaultfalse- On Dialog, AlertDialogMarks the body with aria-busy and gives it a minimum height while the content is on its way. The header, the close button and Escape stay available.
messagesPartial<DialogMessages>- On Dialog, AlertDialogReplaces words of the language in force, key by key: the accessible names of the close and full-screen buttons (close, fullScreen). An aria-label on DialogClose takes precedence.
initialFocus'first' | 'container' | 'cancel' | RefObject | falseDefaultcancel- Where focus goes when the dialog opens. The default, cancel, is the least destructive answer.
finalFocusRefObject | false- On Dialog, AlertDialogWhere focus goes when the dialog closes. Unset, focus returns to the element that had it when the dialog opened, usually the trigger. false leaves focus where it is.
valuestring- On DialogClose, AlertDialogCancel, AlertDialogActionThe result this button closes the dialog with, read from request.result in onOpenChange. AlertDialogCancel defaults to "cancel" and AlertDialogAction to "confirm".
tone'accent' | 'secondary' | 'info' | 'success' | 'warning' | 'danger'Defaultdanger- The kind of decision. It sets the mark AlertDialogIcon draws and its color.
modalbooleanDefaulttrue- Fixed: an alert dialog is always modal.
outsidePress'close' | 'none'Defaultnone- Fixed: a press outside never closes an alert dialog.
back'close' | 'none'Defaultclose- Whether the browser’s way back cancels the confirmation, as Escape does. The close request carries the reason back.
surface'panel' | 'plain'Defaultpanel- Whether AlertDialog paints the panel. plain removes the paint and keeps the behavior.
fullScreen'never' | 'narrow' | 'always'Defaultnever- When the panel fills the whole layer. AlertDialog keeps its margins at every width by default.
Events
| Name | Payload | When |
|---|---|---|
onOpenChange | (open: boolean, request: DialogChangeRequest) | Before the dialog opens or closes, whatever caused it. The request carries the new value, the previous value, the reason (pointer, keyboard, dismiss, escape, outsidePress, back, submit or programmatic), the result of the close, the originating event, and cancel(), which keeps the dialog as it is. One handler therefore guards the ✕, Escape, a press outside, the way back and the ref handle together. |
onOpenChangeComplete | (open: boolean) | After the entrance or the exit has ended: true once the layer is settled open, false once it has left — the moment an application that renders the layer conditionally removes it, so the exit runs. A layer mounted open enters from its closed style, as one opened later does. |
onFullscreenChange | (fullscreen: boolean, request: DialogFullscreenRequest) | Before the panel expands to the whole layer or is restored. The request carries the new value, the previous value, the reason (pointer, keyboard or programmatic), the originating event, and cancel(), which keeps the panel as it is. |
onClick, onKeyDown and the other native events, on every part | the element’s own event | Whenever the element fires them. Your handler runs before the dialog’s own, and calling preventDefault() in it cancels the dialog’s behavior, such as opening on a trigger press or closing on a close press. |
Composition
render(props) => ReactNode- On every partReplaces the element a part renders and passes it every attribute the part writes. Use it to make the trigger, the cancel and the action a Button.
refRef<DialogHandle> on Dialog, Ref<HTMLElement> on every part- On Dialog, AlertDialog, every partOn a part, the element. On Dialog and AlertDialog, a handle with open(), close(result), focus() and content, the panel element once it is rendered.
--slotted-dialog-measurelengthDefault from size- On the root partThe maximum width of the panel, for a width the five sizes do not hold, such as a two-column form at 46rem. Set it with a style attribute on one dialog, with a rule for a region, or once in the theme. It takes precedence over size, and a step token takes precedence over it.
--slotted-dialog-measure-sm, -md, -lg, -xllengthDefault from size- On the root partThe maximum width of one size step, read before --slotted-dialog-measure, so a theme widens one step and keeps the others.
containerElement | null- On Dialog, AlertDialogThe element this dialog is rendered into, instead of the shared portal root. To change the portal root for the whole document, call setPortalContainer from @slotted/core/portal.
useDialog()() => DialogContextValue- On inside Dialog or AlertDialogWhat the parts read: the open state, the ids, the resolved axes and close(reason, result). It throws outside Dialog and AlertDialog.
DialogDefaultsProvider{ size, placement, scroll, surface, mount, fullScreen, modal, escape, outsidePress, back }- On a subtreeSets these ten values once for every dialog under it. A value set on one dialog takes precedence.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, in a portal | Yes | The layer, fixed over the viewport. It carries data-ui="dialog", one attribute per axis, data-open and data-loading, and a z-index of --slotted-z-index-overlay plus the depth of the layer stack, so a dialog opened over another sits above it. It is also the container that fullScreen="narrow" measures, so full screen follows the width of the layer rather than the width of the window. |
trigger | button, or the element render returns | No | The control that opens the dialog. It stays where it is written while the layer is rendered in a portal, and carries aria-haspopup, aria-expanded and aria-controls. A press on it does not count as a press outside the dialog. Rendered as a Button, the element keeps the button’s data-part="root". |
backdrop | div | Yes | The scrim behind the panel, painted from --slotted-scrim. It does not scroll. A non-modal dialog does not paint it and lets the pointer through to the page. |
viewport | div | Yes | The box that positions the panel and, with scroll="viewport", the box that scrolls. A panel taller than the layer aligns to the top edge, so its title stays on screen. |
content | div | Yes | The panel. It carries role="alertdialog" and, while modal, aria-modal="true". It is a grid of three rows, header, body and footer, and only the body row shrinks, so the actions stay on screen when the body is long. It draws no padding: DialogHeader, DialogBody and DialogFooter carry the panel inset. A layout that skips them reads --slotted-dialog-inset-inline and --slotted-dialog-inset-block, which the panel states, and a theme sets the inset with --slotted-dialog-padding-inline and --slotted-dialog-padding-block. |
header | header, or the element render returns | No | Three columns: the mark, the words and the corner buttons. A title that wraps makes the row taller and never pushes the close button off the line. Any other content written in the header, such as a badge, is placed in the words column under the description. |
title | h2, or the element render returns | No | The visible name of the dialog. The panel points aria-labelledby at it only while it is rendered. |
description | p, or the element render returns | Yes | The sentence that says what is about to happen. Required: the alertdialog pattern makes aria-describedby mandatory, and AlertDialog throws an error when it is missing. |
body | div, or the element render returns | No | The row that scrolls. It carries aria-busy while loading is set. Scrolling it to the end does not scroll the page behind a non-modal dialog. |
footer | footer, or the element render returns | No | The actions: a row aligned to the end that wraps when the buttons do not fit, on the sunken surface. Each row of the panel draws the rule above itself, so a panel without a body draws one rule, not two. |
icon | span | No | The mark of the tone, drawn from a glyph, so the kind of decision does not depend on color alone. Under forced colors it is the only signal of the tone. |
cancel | button | Yes | The least destructive answer, and where focus lands when the dialog opens. It closes with the reason dismiss and the result "cancel". Rendered as a Button, the element keeps the button’s data-part="root". |
action | button | Yes | The action being confirmed. It closes with the reason submit and the result "confirm". Rendered as a Button, the element keeps the button’s data-part="root". |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every dialog inside it.
Dialog tokens
| Token | Default |
|---|---|
--slotted-dialog-backdrop-filter | none |
--slotted-dialog-body-color | var(--slotted-text, CanvasText) |
--slotted-dialog-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-dialog-close-active-background | var(--slotted-tone-secondary-subtle-active) |
--slotted-dialog-close-color | var(--slotted-text-muted, GrayText) |
--slotted-dialog-close-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-dialog-color | var(--slotted-text, CanvasText) |
--slotted-dialog-description-color | var(--slotted-text-muted, GrayText) |
--slotted-dialog-footer-gap | var(--slotted-action-gap, 8px) |
--slotted-dialog-footer-surface | var(--slotted-surface-sunken, Canvas) |
--slotted-dialog-measure | calc(var(--slotted-form-measure, 40rem) + 2 * var(--_padding-inline)) |
--slotted-dialog-measure-lg | var(--slotted-dialog-measure, 48rem) |
--slotted-dialog-measure-md | var( --slotted-dialog-measure, calc(var(--slotted-form-measure, 40rem) + 2 * var(--_padding-inline)) ) |
--slotted-dialog-measure-sm | var(--slotted-dialog-measure, 32rem) |
--slotted-dialog-measure-xl | var(--slotted-dialog-measure, 56rem) |
--slotted-dialog-padding-block | var(--slotted-space-7, 1.25rem) |
--slotted-dialog-padding-block-sm | var(--slotted-space-6, 1rem) |
--slotted-dialog-padding-inline | var(--slotted-space-8, 1.5rem) |
--slotted-dialog-padding-inline-sm | var(--slotted-space-7, 1.25rem) |
--slotted-dialog-radius | var(--slotted-radius-lg, 8px) |
--slotted-dialog-rule-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-dialog-scrim | var(--slotted-scrim, Canvas) |
--slotted-dialog-scrim-backdrop-filter | none |
--slotted-dialog-surface | var(--slotted-surface-raised, Canvas) |
--slotted-dialog-title-color | var(--slotted-text, CanvasText) |
--slotted-dialog-title-font-family | var( --slotted-font-family-heading, var(--slotted-font-family-sans, ui-sans-serif, system-ui, sans-serif) ) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-action-gap | comfortable 8px · compact 6px · dense 4px |
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thick | 2px |
--slotted-border-width-thin | 1px |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-icon-size-lg | comfortable 18px · compact 16px · dense 14px |
--slotted-control-inner-size-lg | comfortable 28px · compact 24px · dense 22px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-duration-long | 320ms |
--slotted-duration-medium | 200ms |
--slotted-duration-short | 120ms |
--slotted-easing-exit | cubic-bezier(0.3, 0, 0.8, 0.15) |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-heading | var(--slotted-font-family-sans) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-lg | 1rem |
--slotted-font-size-md | 0.875rem |
--slotted-font-size-xl | 1.125rem |
--slotted-font-weight-semibold | 600 |
--slotted-form-measure | 40rem |
--slotted-line-height-md | 1.5 |
--slotted-radius-lg | 8px |
--slotted-radius-sm | 4px |
--slotted-scrim | Set per scheme by the theme |
--slotted-shadow-lg | Set per scheme by the theme |
--slotted-space-12 | 4rem |
--slotted-space-2 | 0.25rem |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-space-6 | 1rem |
--slotted-space-7 | 1.25rem |
--slotted-space-8 | 1.5rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-surface-sunken | Set per scheme by the theme |
--slotted-target-comfortable | 44px |
--slotted-target-min | 24px |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-accent-text | Set per scheme by the theme |
--slotted-tone-danger-text | Set per scheme by the theme |
--slotted-tone-info-text | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |
--slotted-tone-secondary-text | Set per scheme by the theme |
--slotted-tone-success-text | Set per scheme by the theme |
--slotted-tone-warning-text | Set per scheme by the theme |
--slotted-z-index-overlay | 1000 |