Skip to content
FrameworkStyle

media-alert-dialog

A modal alert dialog for urgent messages that require acknowledgement

Import

import '@videojs/html/ui/alert-dialog';

Anatomy

<media-alert-dialog>
  <media-dialog-backdrop></media-dialog-backdrop>
  <media-dialog-popup>
    <media-dialog-title></media-dialog-title>
    <media-dialog-description></media-dialog-description>
    <media-dialog-close></media-dialog-close>
  </media-dialog-popup>
</media-alert-dialog>

Behavior

Use an alert dialog for an urgent message that interrupts the user and requires acknowledgement. Your application controls when it opens and supplies its content. AlertDialog.Root adds alert semantics, while the other AlertDialog parts are re-exported from Dialog. For general modal content, including a player opened from a thumbnail, use Dialog.Root instead.

Set the root’s open property to show the dialog. The root supplies alert state while the shared media-dialog-backdrop and media-dialog-popup siblings render the visual surfaces and semantics. The root updates the property and dispatches open-change when the dialog closes.

The close part and Escape close the dialog. The dialog stays rendered during a closing transition, then restores focus to the element that was focused before it opened.

Styling

Use the open and transition data attributes to style visibility and animations:

Attribute Description
data-open Present while the dialog is open, including its closing transition
data-starting-style Present at the start of the opening transition
data-ending-style Present during the closing transition
media-dialog-backdrop:not([data-open]),
media-dialog-popup:not([data-open]) {
  display: none;
}

media-dialog-backdrop[data-starting-style],
media-dialog-backdrop[data-ending-style],
media-dialog-popup[data-starting-style],
media-dialog-popup[data-ending-style] {
  opacity: 0;
}

Accessibility

The dialog uses role="alertdialog" and aria-modal="true". The title and description receive generated IDs that are connected with aria-labelledby and aria-describedby. Focus moves into the dialog when it opens, stays within it while open, and returns to the previously focused element when it closes. Content outside the dialog is inert while it is open. Pressing Escape closes the dialog.

Examples

Basic usage

Stop playback? Your current playback position will be lost. Continue
<div class="html-alert-dialog-basic">
  <button class="html-alert-dialog-basic__trigger" type="button">Open alert dialog</button>
  <media-alert-dialog>
    <media-dialog-backdrop class="html-alert-dialog-basic__backdrop"></media-dialog-backdrop>
    <media-dialog-popup class="html-alert-dialog-basic__dialog">
      <media-dialog-title class="html-alert-dialog-basic__title">Stop playback?</media-dialog-title>
      <media-dialog-description class="html-alert-dialog-basic__description">
        Your current playback position will be lost.
      </media-dialog-description>
      <media-dialog-close class="html-alert-dialog-basic__close">Continue</media-dialog-close>
    </media-dialog-popup>
  </media-alert-dialog>
</div>

API Reference

media-alert-dialog

Manages alert dialog state and provides it to the shared dialog parts.

Props

PropTypeDefaultDetails
closeOnEscapeboolean
defaultOpenboolean
openboolean

State

State is reflected as data attributes for CSS styling.

PropertyTypeDetails
transitionStartingboolean
transitionEndingboolean
openboolean
status'idle' | 'starting' | 'ending'
titleIdstring | undefined
descriptionIdstring | undefined

Events

EventDescription
open-changeFired when the dialog's open state changes.
open-change-complete

media-dialog-backdrop

Presentational layer behind a dialog while it is rendered, including its exit transition.

Data attributes

AttributeTypeDetails
data-open
data-starting-style
data-ending-style

media-dialog-close

Renders a button that closes the dialog.

Data attributes

AttributeTypeDetails
data-open
data-starting-style
data-ending-style

media-dialog-description

Renders the description announced with the dialog.

Renders the modal dialog while it is open.

AttributeTypeDetails
data-open
data-starting-style
data-ending-style

media-dialog-title

Renders the heading that labels the dialog.