Dialog
A modal window for a question or short task that blocks the page.
SourceStyles source@monoline/react 0.4.0Markdown for AI toolsstable
- Built on native <dialog>
- 8 parts, named exports
- role=dialog with aria-modal; the title names it and the description describes it.
- Focus moves into the dialog, is trapped there, and returns to the trigger on close.
- Escape and the Close button close it; the page behind is inert.
- Styles in one file:
dialog.css
Import
import '@monoline/css';
import {Dialog} from '@monoline/react';
Not installed yet? Pick a route.
Copies the source and its styles into your project.
npx monoline add dialog
Usage
import {Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger} from '@monoline/react';
<Dialog>
<DialogTrigger asChild><Button variant="line">Overwrite copy</Button></DialogTrigger>
<DialogContent>
<DialogHeader><DialogTitle>Overwrite the remote copy?</DialogTitle><DialogDescription>The copy on this device is newer. Changes from 12 March on the other device will be lost.</DialogDescription></DialogHeader>
<DialogFooter><DialogClose asChild><Button variant="line">Keep both</Button></DialogClose><DialogClose asChild><Button variant="solid">Overwrite</Button></DialogClose></DialogFooter>
</DialogContent>
</Dialog>
Anatomy
Import the parts you need and nest them like this.
import {Dialog, DialogTrigger, DialogClose, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription} from '@monoline/react';
<Dialog>
<DialogTrigger />
<DialogClose />
<DialogContent />
<DialogHeader />
<DialogFooter />
<DialogTitle />
<DialogDescription />
</Dialog>
Examples
Confirm
Use a dialog only when an action cannot be undone. Otherwise run it and offer Undo.
Props
DialogContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
showClose | boolean | true | Shows a "Close" text button in the corner. Escape and the backdrop always close it. |
Data Attributes
State is exposed through attributes. Style it with these selectors, not with class toggles.
This component sets no state attributes.
CSS classes
| Class | Stylesheet |
|---|---|
.command | dialog.css |
.dialog-close | dialog.css |
.dialog-content | dialog.css |
.dialog-description | dialog.css |
.dialog-footer | dialog.css |
.dialog-header | dialog.css |
.dialog-overlay | dialog.css |
.dialog-title | dialog.css |
.drawer-content | dialog.css |
Customization
Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.
.command {
border-color: var(--accent);
}
Try the props
Change a prop and the component above updates; the code below is what you would write. To edit the code itself, use the Playground.
<Dialog>
<DialogTrigger asChild>
<Button>Open dialog</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Delete project</DialogTitle>
<DialogDescription>This removes the project and its files. You cannot undo it.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose asChild>
<Button>Cancel</Button>
</DialogClose>
<Button variant="danger">Delete</Button>
</DialogFooter>
</DialogContent>
</Dialog>
Accessibility
- role=dialog with aria-modal; the title names it and the description describes it.
- Focus moves into the dialog, is trapped there, and returns to the trigger on close.
- Escape and the Close button close it; the page behind is inert.