overlayshwc
z-dialogDialog
Modal dialog with a backdrop overlay, centered/contained/full presentations, focus management, and stacked overlays.
Attributes
Inherited from DialogMixin
| Attribute | Type | Default | Description |
|---|---|---|---|
open | boolean · reflects | false | Opens the dialog on first render and stays in sync with show() and hide(). |
center | boolean | false | Vertically centers the panel within the overlay. |
container | boolean | false | Adds z-modal-container to the overlay for a contained presentation. |
full | boolean | false | Adds z-modal-full to the overlay for a full-screen presentation. |
stack | boolean | false | Keeps other open dialogs open; without it, showing this dialog hides them. Stacked overlays receive increasing z-index. |
inline | boolean | false | Keeps the component in its original DOM position instead of teleporting it to document.body. |
no-bg-close | boolean | false | Disables closing when the overlay background is clicked. |
no-esc-close | boolean | false | Disables closing with the Esc key. |
unmount | boolean | false | Removes the rendered DOM after the close transition; the next show mounts it again. |
dialog-role | 'dialog' | 'alertdialog' | 'dialog' | ARIA role of the panel: dialog or alertdialog. |
aria-label | string | '' | Accessible name for the panel when no aria-labelledby is set. |
aria-labelledby | string | '' | Id of the element that names the panel; takes precedence over aria-label. |
Inherited from Hwc
| Attribute | Type | Default | Description |
|---|---|---|---|
i18n | string | '' | Per-instance text overrides as key: text pairs, merged over the global z-i18n script and the built-in defaults. |
floating | string | '' | Floating UI placement options (for example offset and shiftPadding) parsed as key: value pairs. |
force-prevent-rerender | boolean | false | Skips re-rendering after the first render; an existing data-host-inner child is adopted as the rendered DOM. |
template | string | '' | Selector or id of an external element or <template> whose inner content is cloned in place of an inline template[data-fn="template"] child. |
Inherited from Base
| Attribute | Type | Default | Description |
|---|---|---|---|
cls | string | '' | Adds classes to named parts as key: classes pairs; a plain string targets the default part. |
stl | string | '' | Adds inline styles to named parts as key: styles pairs; a plain string targets the default part. |
Custom Styling (cls / stl)
Default cls target:dialog · defaultstl target:dialog
| Key | Default class | cls | stl | Description |
|---|---|---|---|---|
dialog | z-modal-dialog | yes | yes | The dialog panel inside the overlay (default z-modal-dialog); the default cls/stl target. |
overlay | z-modal | yes | yes | The fixed backdrop covering the viewport (default z-modal). |
CSS Variables
| Variable | Default | Scope | Description |
|---|---|---|---|
--z-modal-dialog-border-color | var(--z-border) | .z-modal-dialog | Border base color, mixed with transparency using --z-modal-dialog-border-color-o. |
--z-modal-dialog-border-color-o | var(--z-border-o) | .z-modal-dialog | Border opacity percentage used in the border color mix. |
--z-modal-dialog-border-width | 1px | .z-modal-dialog | Border width of the panel. |
--z-modal-dialog-transform | scale(0.96) | .z-modal-dialog | Initial transform of the closed panel (animated to identity on open). |
--z-modal-dialog-transition | 0.12s cubic-bezier(0.16, 1, 0.3, 1) | .z-modal-dialog | Transition timing of the panel opacity/transform. |
--z-modal-dialog-width | 32rem | .z-modal-dialog | Width of the dialog panel (max 100% of the overlay). |
--z-modal-overlay-bg | #000 | .z-modal | Backdrop base color, mixed with transparency using --z-modal-overlay-bg-o. |
--z-modal-overlay-bg-o | 80% | .z-modal | Backdrop opacity percentage used in the background mix. |
--z-modal-overlay-blur | var(--z-global-blur) | .z-modal | Backdrop blur radius used by .z-modal-blur. |
--z-modal-padding | 1rem | .z-modal | Base padding shared by the overlay and panel sections. |
--z-modal-padding-body | var(--z-modal-padding) | .z-modal | Padding of the body section. |
--z-modal-padding-bottom-scrollable | 0 | .z-modal | Bottom padding of a scrollable body directly after the header. |
--z-modal-padding-footer | var(--z-modal-padding) | .z-modal | Padding of the footer section. |
--z-modal-padding-header | var(--z-modal-padding) | .z-modal | Padding of the header section. |
--z-modal-padding-top-after-header | 0 | .z-modal | Top padding of a footer that follows a header (no body between). |
--z-modal-padding-top-after-scrollable | var(--z-modal-padding) | .z-modal | Top padding of a footer directly after a scrollable body. |
--z-modal-padding-top-between | 0 | .z-modal | Top padding of a section directly following another section. |
--z-modal-radius | var(--z-global-radius) | .z-modal | Corner radius of the dialog panel. |
--z-modal-title-line-height | 1 | .z-modal-title | Line height of the dialog title. |
--z-modal-title-size | 1.125rem | .z-modal-title | Font size of the dialog title. |
--z-modal-title-tracking | -0.025em | .z-modal-title | Letter spacing of the dialog title. |
--z-modal-title-weight | 600 | .z-modal-title | Font weight of the dialog title. |
--z-modal-transition | opacity 0.12s cubic-bezier(0.16, 1, 0.3, 1) | .z-modal | Transition of the overlay opacity. |
--z-modal-z-index | 1010 | .z-modal | Stacking order of the overlay. |
Events
| Event | Detail | Flags | Description |
|---|---|---|---|
z-dialog:before-hide · from DialogMixin | — | cancelable, bubbles | Fires before closing; call preventDefault() to abort. |
z-dialog:before-show · from DialogMixin | — | cancelable, bubbles | Fires before opening; call preventDefault() to abort. |
z-dialog:destroy · from DialogMixin | — | bubbles | Fires when the mounted DOM is removed, via unmount or destroy(). |
z-dialog:hidden · from DialogMixin | — | bubbles | Fires after the close transition completes and focus is restored to the opener. |
z-dialog:hide · from DialogMixin | — | bubbles | Fires when the dialog starts closing. |
z-dialog:mount · from DialogMixin | — | bubbles | Fires once when the dialog DOM is first mounted. |
z-dialog:show · from DialogMixin | — | bubbles | Fires when the dialog starts opening, before the transition completes. |
z-dialog:shown · from DialogMixin | — | bubbles | Fires after the open transition completes. |
Methods
| Signature | Description |
|---|---|
destroy(removeHost?: boolean = false): Promise<void> | Closes and unmounts the dialog DOM; optionally removes the host element as well. |
hide(): Promise<void> | Closes the dialog and restores focus to the opener. |
show(trigger?: HTMLElement | null): Promise<void> | Opens the dialog; the trigger element receives focus back on close. |
toggle(trigger?: HTMLElement | null): Promise<void> | Opens the dialog if closed, otherwise closes it. |
Data Hooks
| Attribute | Values | Applies to | Role | Description |
|---|---|---|---|---|
data-close · from DialogMixin | — | external-trigger | trigger | Clicking the element closes the dialog matched by the selector (usually #id). |
data-host-inner · from Hwc | — | descendant | config | Marks the rendered inner wrapper so force-prevent-rerender can adopt server-rendered DOM without re-rendering. |
data-open · from DialogMixin | — | external-trigger | trigger | Clicking the element opens the dialog matched by the selector without toggling. |
data-part | dialog, overlay | descendant | marker | Marks the overlay and panel in adopted server-rendered DOM: data-part="overlay" and data-part="dialog". |
data-reactive · from Hwc | — | descendant | config | Opts the marked child (config script, data source, icons, or template) into live re-parsing when its DOM mutates. |
data-toggle · from DialogMixin | — | external-trigger | trigger | Clicking the element toggles the dialog matched by the selector (usually #id). |
Child Content
script[data-fn="config"][type="application/json"]
JSON configuration script parsed by the base class (i18n, cls, stl, floating).
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | config | Marks the script as configuration (value: config). |
data-reactive | no | boolean | Re-parses the configuration when the script mutates. |
select[data-fn="data-source"]
Hidden select parsed into grouped option data by the base class.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | data-source | Marks the select as the data source (value: data-source). |
data-reactive | no | boolean | Re-parses the options when the select mutates. |
optgroup · repeatable
Groups options under a label.
| Attribute | Required | Type | Description |
|---|---|---|---|
label | yes | string | Group header text; also the default group key. |
disabled | no | boolean | Disables every option in the group. |
data-key | no | string | Overrides the group key used in the parsed data. |
data-keywords | no | comma-separated string | Comma-separated keywords stored with the group's data. |
option · repeatable
One option entry within the group.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Value carried by this option in the parsed data. |
disabled | no | boolean | Makes the option non-selectable. |
selected | no | boolean | Marks the option as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated; searched alongside the label and value. |
option · repeatable
One ungrouped option entry.
| Attribute | Required | Type | Description |
|---|---|---|---|
value | no | string | Value carried by this option in the parsed data. |
disabled | no | boolean | Makes the option non-selectable. |
selected | no | boolean | Marks the option as initially selected. |
data-keywords | no | comma-separated string | Extra search terms, comma-separated. |
template[data-fn="icons"]
Instance-level icon repository.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | icons | Marks the template as an icon source (value: icons). |
data-reactive | no | boolean | Re-parses the icons when the template mutates. |
* · repeatable
One icon element.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-key | yes | string | Icon key referenced by $icons. |
template[data-fn="template"]
Deferred content template mounted by the base class.
| Attribute | Required | Type | Description |
|---|---|---|---|
data-fn | yes | template | Marks the template for deferred mounting (value: template). |
data-reactive | no | boolean | Re-parses the template when it mutates. |
CSS Classes
| Class | Role | Applies to | Description |
|---|---|---|---|
.z-modal | root | z-dialog | Overlay root: fixed, scrollable backdrop with the dimmed background. |
.z-modal-blur | modifier | .z-modal | Applies a backdrop blur to the overlay. |
.z-modal-body | element | .z-modal | Panel body section with its own padding. |
.z-modal-container | element | .z-modal | Contained presentation: widens the panel to a large fixed width. |
.z-modal-dialog | state | .z-modal | The dialog panel: centered, bordered, rounded card that scales/fades in. |
.z-modal-footer | element | .z-modal | Panel footer section with its own padding. |
.z-modal-full | element | .z-modal | Full-screen presentation: no overlay padding, panel fills the viewport. |
.z-modal-header | element | .z-modal | Panel header section with its own padding. |
.z-modal-page | element | .z-modal | Applied to the page root to clip page scroll while the dialog is open. |
.z-modal-title | element | .z-modal | Dialog title typography (size, weight, tracking). |
Accessibility
| Part | ARIA | Description |
|---|---|---|
dialog | aria-label="${ifDefined(aria.ariaLabel)}" aria-labelledby="${ifDefined(aria.labelledBy)}" aria-modal="true" role="${aria.role}" | Dialog panel: aria-modal="true" with the configured dialog/alertdialog role, named via aria-label or aria-labelledby. |
overlay | — | Backdrop wrapper; no ARIA attributes of its own. |
- The panel is
aria-modal="true"with the configureddialog/alertdialogrole; focus moves into the panel on open and back to the opener on close. - Structure panel content with
.z-modal-header,.z-modal-body, and.z-modal-footer; give the dialog an accessible name viaaria-labeloraria-labelledby.