Skip to content
FrameworkStyle

ErrorDialog

An alert dialog that presents and dismisses playback errors

Import

import { ErrorDialog } from '@videojs/react';

Anatomy

<ErrorDialog.Root>
  <ErrorDialog.Backdrop />
  <ErrorDialog.Popup>
    <ErrorDialog.Title />
    <ErrorDialog.Description />
    <ErrorDialog.Close />
  </ErrorDialog.Popup>
</ErrorDialog.Root>

Behavior

ErrorDialog is a specialized root driven by the player’s error feature. It uses alert semantics and reuses the backdrop, popup, title, description, and close parts from Dialog; it is not nested inside AlertDialog. It opens when the attached media reports an error and stays hidden otherwise. Closing it dismisses the current error in the player store.

The title, description, and close label use localized default text. Provide children to any of those parts to replace its default content. Known media error codes use the matching translated message, while custom error messages are shown as written.

The included player skins already render an error dialog. Compose this component directly when building a custom skin.

Styling

Use data-open, data-starting-style, and data-ending-style to style visibility and transitions.

React renders the backdrop and popup as separate DOM elements. Add a className to each part and style their transitions independently:

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

Accessibility

The popup uses role="alertdialog". Its title and description are connected with aria-labelledby and aria-describedby.

Modality is scoped to the player container rather than the page. While the error is open, the rest of the container is inert and focus that lands elsewhere inside it returns to the popup, but content outside the player stays interactive and aria-modal is omitted. Only when the popup renders outside the container does the dialog fall back to document-wide modality: aria-modal="true", Tab cycling within the popup, and everything outside it inert.

Pressing Escape or activating the close part dismisses the error.

Examples

The example replaces the video source with invalid local data so the media element reports an error without making a failing network request.

Basic usage

import { Container, createPlayer, ErrorDialog } from '@videojs/react';
import { Video, videoFeatures } from '@videojs/react/video';
import { useRef } from 'react';

const { Player } = createPlayer({ features: videoFeatures });
const brokenSource = 'data:video/mp4;base64,AAAA';

export default function BasicUsage() {
  const videoRef = useRef<HTMLVideoElement>(null);

  const triggerError = () => {
    const video = videoRef.current;
    if (!video) return;

    video.src = brokenSource;
    video.load();
  };

  return (
    <Player>
      <Container className="react-error-dialog-basic">
        <Video
          ref={videoRef}
          className="react-error-dialog-basic__video"
          src="https://stream.mux.com/BV3YZtogl89mg9VcNBhhnHm02Y34zI1nlMuMQfAbl3dM/highest.mp4"
          autoPlay
          muted
          playsInline
          loop
        />
        <button className="react-error-dialog-basic__trigger" type="button" onClick={triggerError}>
          Trigger a playback error
        </button>
        <ErrorDialog.Root>
          <ErrorDialog.Backdrop className="react-error-dialog-basic__backdrop" />
          <ErrorDialog.Popup className="react-error-dialog-basic__dialog">
            <ErrorDialog.Title className="react-error-dialog-basic__title" />
            <ErrorDialog.Description className="react-error-dialog-basic__description" />
            <ErrorDialog.Close className="react-error-dialog-basic__close" />
          </ErrorDialog.Popup>
        </ErrorDialog.Root>
      </Container>
    </Player>
  );
}

API Reference

Root

Opens from player error state and provides it to the shared dialog parts.

State

State is accessible via the render, className, and style props.

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

Close

Renders a localized button that closes the dialog and dismisses the player error.

Props

PropTypeDefaultDetails
classNamestring | ((state: DialogCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: DialogCore.State) => ReactElement | null)
styleCSSProperties | ((state: DialogCore.State) => CSSProperties | undefined)

Description

Renders the localized playback error message, or authored children when provided.

Props

PropTypeDefaultDetails
classNamestring | ((state: DialogCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: DialogCore.State) => ReactElement | null)
styleCSSProperties | ((state: DialogCore.State) => CSSProperties | undefined)

Title

Renders the localized error dialog heading, or authored children when provided.

Props

PropTypeDefaultDetails
classNamestring | ((state: DialogCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: DialogCore.State) => ReactElement | null)
styleCSSProperties | ((state: DialogCore.State) => CSSProperties | undefined)

Backdrop

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

Props

PropTypeDefaultDetails
classNamestring | ((state: DialogCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: DialogCore.State) => ReactElement | null)
styleCSSProperties | ((state: DialogCore.State) => CSSProperties | undefined)

Data attributes

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

Renders the modal dialog while it is open.

PropTypeDefaultDetails
classNamestring | ((state: DialogCore.State) => string | undefined)
renderReactElement | ((props: HTMLProps, state: DialogCore.State) => ReactElement | null)
styleCSSProperties | ((state: DialogCore.State) => CSSProperties | undefined)
AttributeTypeDetails
data-open
data-starting-style
data-ending-style