Skip to content

ReferenceDialogs

media-alert-dialog

A modal alert dialog for urgent messages that require acknowledgement

Import

import '@videojs/html/ui/alert-dialog';
import '@videojs/html/ui/dialog-backdrop';
import '@videojs/html/ui/dialog-popup';
import '@videojs/html/ui/dialog-title';
import '@videojs/html/ui/dialog-description';
import '@videojs/html/ui/dialog-close';

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.

<media-alert-dialog> adds alert semantics, while the other parts are the same elements <media-dialog> uses. For general modal content, including a player opened from a thumbnail, use <media-dialog> 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

A modal dialog with alert semantics.

Props

PropTypeDefaultDetails
closeOnEscape
attribute close-on-escape
boolean—
defaultOpen
attribute default-open
boolean—
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 backdrop that reflects its owning dialog's state.

Data attributes

AttributeDescription
data-openPresent when the dialog is open.
data-starting-stylePresent during the open transition.
data-ending-stylePresent during the close transition.

media-dialog-close

Button that closes its owning dialog; the element itself takes role="button" and keyboard focus.

Data attributes

AttributeDescription
data-openPresent when the dialog is open.
data-starting-stylePresent during the open transition.
data-ending-stylePresent during the close transition.

media-dialog-description

Text announced as its owning dialog's description. The element takes the id that the popup's aria-describedby points to.

Semantic popup that owns focus management and dialog transition completion.

AttributeDescription
data-openPresent when the dialog is open.
data-starting-stylePresent during the open transition.
data-ending-stylePresent during the close transition.

media-dialog-title

Text that labels its owning dialog. The element takes the id that the popup's aria-labelledby points to.