Dialog
A modal window for focused tasks such as editing a record or filling a short form.
Status: beta. Category: Overlays.
import { Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@glyphui/ui'
Exports: Dialog, DialogTrigger, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogBody, DialogFooter, DialogClose, dialogStyles.
Notes
- Focus moves into the dialog on open, is trapped while open, and returns to the trigger on close.
- Always render a DialogTitle; it becomes the dialog’s accessible name.
- Escape and clicking the backdrop close it. For decisions that must not be dismissed by accident, use AlertDialog.
Example: Edit form
import {
Button,
Dialog,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
Field,
Input,
} from '@glyphui/ui'
export default function Example() {
return (
<Dialog>
<DialogTrigger asChild>
<Button variant="outline">Edit profile</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>
Your name and handle are visible to everyone in the workspace.
</DialogDescription>
</DialogHeader>
<DialogBody className="grid gap-4">
<Field label="Name">
<Input defaultValue="Ada Lovelace" />
</Field>
<Field label="Handle">
<Input prefix="@" defaultValue="ada" />
</Field>
</DialogBody>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<DialogClose asChild>
<Button>Save changes</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
Example: Sizes
sm, md (default), lg and xl set the maximum width.
import {
Button,
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
DialogTrigger,
} from '@glyphui/ui'
const sizes = ['sm', 'md', 'lg', 'xl'] as const
export default function Example() {
return (
<div className="flex flex-wrap gap-2">
{sizes.map((size) => (
<Dialog key={size}>
<DialogTrigger asChild>
<Button variant="outline">{size}</Button>
</DialogTrigger>
<DialogContent size={size}>
<DialogHeader>
<DialogTitle>Size {size}</DialogTitle>
<DialogDescription>
The panel never grows past the viewport and scrolls when content is tall.
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
))}
</div>
)
}
Live page: https://glyphui.xyz/components/dialog