v2.0.0-rc.4
Theme

Dialog

<el-dm-dialog> wraps a native HTML <dialog> and applies @duskmoon-dev/core dialog styles. Opening uses showModal() so you get the browser’s focus trap, Escape handling, and ::backdrop. Invoker Commands (command / commandfor) are forwarded to the inner native dialog (show-modal, close, request-close).

Installation

npm install @duskmoon-dev/el-dialog

Usage

import '@duskmoon-dev/el-dialog/register';
<button command="show-modal" commandfor="my-dialog">Open Dialog</button>

<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>

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-dismissbooleanfalsePrevent closing via backdrop or Escape
no-backdropbooleanfalseOpen as non-modal (no ::backdrop)

Methods

MethodDescription
show()Opens the dialog as a modal (showModal())
showModal()Alias for show()
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 native <dialog> element
boxInner dialog-box container
headerThe header section
titleThe title wrapper
bodyThe body section
footerThe footer section
closeThe close button

Backdrop styling uses native ::backdrop. Override --color-scrim to change the overlay color.

Accessibility

  • Native <dialog> provides role="dialog" and modal semantics
  • showModal() traps focus and restores it on close
  • Escape fires cancel; dismissible dialogs close, no-dismiss prevents it
  • Backdrop is native ::backdrop, not a custom overlay