Dialog

The Dialog component provides a modal overlay for displaying content that requires user attention.

Installation

npm install @duskmoon-dev/el-dialog

Usage

import '@duskmoon-dev/el-dialog/register';
<el-dm-dialog id="my-dialog">
  <span slot="header">Dialog Title</span>
  <p>Dialog content goes here.</p>
  <div slot="footer">
    <el-dm-button variant="ghost" onclick="document.querySelector('#my-dialog').close()">Cancel</el-dm-button>
    <el-dm-button variant="primary">Confirm</el-dm-button>
  </div>
</el-dm-dialog>

<el-dm-button onclick="document.querySelector('#my-dialog').show()">Open Dialog</el-dm-button>

Live Demo

Dialog Demo

Open DialogExample Dialog

This is an example dialog. You can put any content here.

Close

Properties

PropertyTypeDefaultDescription
openbooleanfalseWhether the dialog is visible
size'sm' | 'md' | 'lg' | 'xl' | 'full''md'Dialog size
dismissiblebooleantrueAllow closing via backdrop click or Escape
no-backdropbooleanfalseHide the backdrop overlay

Methods

MethodDescription
show()Opens the dialog
close()Closes the dialog
toggle()Toggles the dialog state

Sizes

<el-dm-dialog size="sm">Small dialog</el-dm-dialog>
<el-dm-dialog size="md">Medium dialog</el-dm-dialog>
<el-dm-dialog size="lg">Large dialog</el-dm-dialog>
<el-dm-dialog size="xl">Extra large dialog</el-dm-dialog>
<el-dm-dialog size="full">Fullscreen dialog</el-dm-dialog>

Slots

SlotDescription
defaultMain dialog content
headerDialog header/title
footerDialog footer/actions

Events

EventDescription
openFired when dialog opens
closeFired when dialog closes

Event Handling

const dialog = document.querySelector('el-dm-dialog');
dialog.addEventListener('open', () => {
  console.log('Dialog opened');
});
dialog.addEventListener('close', () => {
  console.log('Dialog closed');
});

CSS Parts

PartDescription
dialogThe dialog container
backdropThe backdrop overlay
headerThe header section
bodyThe body section
footerThe footer section
closeThe close button

Accessibility

  • Uses role="dialog" and aria-modal="true"
  • Escape key closes dismissible dialogs
  • Focus is trapped within the dialog when open
  • Body scroll is disabled when dialog is open