Overlay

Dialog

Modal dialog with accessible focus trap.

Available inreactangular

Preview

Live previewreal component

Install

TerminalBash
npx @mcp-elements/cli add dialog

Usage

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

PropTypeDefaultDescription
open *booleanWhether the dialog is open
onOpenChange(open: boolean) => voidCalled when open state should change
modalbooleantrueWhether to trap focus inside the dialog