Skip to content
FrameworkStyle

media-dialog

A modal dialog for application content, including players opened from a thumbnail

Import

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

Anatomy

<button commandfor="video-dialog">Open video</button>
<media-dialog id="video-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-dialog>

Behavior

Dialog provides the modal interaction and accessibility behavior while your application supplies the content and styling. It is the general-purpose replacement for a ModalDialog use case such as opening a player from a thumbnail.

Place a button immediately before media-dialog, or connect them explicitly with commandfor and an id. You can also set the dialog’s open property directly. The root provides state without creating a layout box; media-dialog-backdrop and media-dialog-popup are sibling surfaces. The element dispatches open-change when its state changes and open-change-complete after the popup transition finishes.

The close part and Escape close the dialog. Other buttons inside the dialog, including player controls, do not close it.

Your application decides what opening and closing mean for the media. The example starts playback after opening and pauses it as soon as the dialog closes. Handle the promise returned by play(), since browsers can reject autoplay when it is not allowed.

Use AlertDialog for urgent messages that require acknowledgement. ErrorDialog is the player-error specialization. Both use the same dialog behavior.

Styling

Use the open and transition data attributes to style the modal and its 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 popup uses role="dialog" and aria-modal="true". Include Dialog.Title so the dialog always has an accessible name. Dialog.Description is optional. These parts receive generated IDs connected through aria-labelledby and aria-describedby. The trigger receives aria-haspopup, aria-controls, and aria-expanded.

When the dialog opens, focus moves to an element with autofocus, the first focusable element, or the popup itself. Tab and Shift + Tab keep focus within the dialog, and content outside the dialog becomes inert. Closing restores focus to the trigger, or to the element that was focused before the dialog opened.

Dialogs inside the same player container share modal coordination. Opening one closes the current dialog and dismisses any open menu, tooltip, or popover before focus moves into the new popup.

Examples

Player modal

Open the video from its thumbnail. Playback starts when the dialog opens and pauses when it closes.

Video title A video opened from a thumbnail. Close
<div class="html-dialog-basic">
  <button class="html-dialog-basic__trigger" type="button" commandfor="html-video-dialog">
    <img src="https://image.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/thumbnail.jpg" alt="" />
    <span>Play the video</span>
  </button>
  <media-dialog id="html-video-dialog">
    <media-dialog-backdrop class="html-dialog-basic__backdrop"></media-dialog-backdrop>
    <media-dialog-popup class="html-dialog-basic__dialog">
      <div class="html-dialog-basic__popup">
        <media-dialog-title class="html-dialog-basic__title">Video title</media-dialog-title>
        <media-dialog-description class="html-dialog-basic__description">
          A video opened from a thumbnail.
        </media-dialog-description>
        <media-dialog-close class="html-dialog-basic__close">Close</media-dialog-close>
        <video-player>
          <media-container>
            <video src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4" controls muted playsinline></video>
          </media-container>
        </video-player>
      </div>
    </media-dialog-popup>
  </media-dialog>
</div>

API Reference

media-dialog

Manages dialog state and provides it to the compound parts.

Props

PropTypeDefaultDetails
closeOnEscapebooleantrue
defaultOpenbooleanfalse
openbooleanfalse

State

State is reflected as data attributes for CSS styling.

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

Data attributes

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

Events

EventDescription
open-change
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.