Dialog

Material Design 3 dialog web component, built on the native <dialog> element.

  • 4.3 KB gzipped
  • @lit-material/dialog 0.2.0
  • Renders on the server

Example

Install

npm install @lit-material/dialog @lit-material/tokens
import "@lit-material/dialog";

Link @lit-material/tokens/css/index.css once per page for the colour, type and shape tokens. Install guide

API

<lit-material-dialog>

Material Design 3 (basic) dialog, built on the native <dialog> element — so focus trapping, initial focus, top-layer stacking, and Escape-to-close all come from the browser rather than reimplemented JS.

Properties

PropertyAttributeTypeDefaultDescription
openopenbooleanfalse
disableBackdropClosedisable-backdrop-closebooleanfalseIf set, clicking the backdrop (outside the visible card) does not close the dialog.
returnValueproperty onlystringnoneThe value the dialog was closed with (via close() or a method="dialog" form submit).

Events

EventDescription
closeRe-dispatched from the native close event, after the dialog has closed.
cancelRe-dispatched from the native cancel event (fired on Escape, before close). Cancelable: calling preventDefault() stops the dialog from closing.

Slots

SlotDescription
iconAn optional small icon shown centered above the headline.
headlineThe dialog's title.
defaultThe dialog's body content (supporting text, form fields, etc.).
actionsAction buttons, right-aligned. A <form method="dialog"> submit button inside this slot closes the dialog natively and sets returnValue, without any extra JS.

CSS parts

PartDescription
dialogThe native <dialog> element. Transparent and sized to the viewport so clicks outside container can be detected as backdrop clicks; style the visible card via container instead.
containerThe visible card (background, padding, shape, elevation).

Source on GitHub npm