ReferenceDialogs
Dialog
A modal dialog for application content, including players opened from a thumbnail
Import
Anatomy
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.
Use Dialog.Trigger to open the dialog. Use open with onOpenChange for controlled state, or defaultOpen for uncontrolled state. Root provides state without rendering an element, while Popup renders only while the dialog is open or closing.
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:
React renders the backdrop and popup as separate DOM elements. Add a className to each part and style their transitions independently:
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.