Overlay
Dialog
Modal dialog with accessible focus trap.
Available in
reactangularPreview
Live previewreal component
Install
TerminalBash
npx @mcp-elements/cli add dialogUsage
dialog-example.tsxTSX
import { Dialog, DialogHeader, DialogTitle, DialogFooter } from '@mcp-elements/react'
import { useState } from 'react'
export function Example() {
const [open, setOpen] = useState(false)
return (
<>
<button onClick={() => setOpen(true)}>Open dialog</button>
<Dialog open={open} onOpenChange={setOpen}>
<DialogHeader>
<DialogTitle>Confirm action</DialogTitle>
</DialogHeader>
<p>Are you sure you want to proceed?</p>
<DialogFooter>
<button onClick={() => setOpen(false)}>Cancel</button>
<button onClick={() => setOpen(false)}>Confirm</button>
</DialogFooter>
</Dialog>
</>
)
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
open * | boolean | — | Whether the dialog is open |
onOpenChange | (open: boolean) => void | — | Called when open state should change |
modal | boolean | true | Whether to trap focus inside the dialog |