GooseUI

Components

Video Dialog

New

A poster with a play button that opens a modal player. The modal is a native <dialog>: the button opens it through invoker commands (commandfor and command="show-modal"), so it works without JavaScript, and the browser handles focus, Esc and the inert page. A client island of about 0.5 kB starts the video right inside the click, so Safari allows sound, and pauses it on close. Without JavaScript the player opens with controls and the viewer presses play.

Browser Support

<dialog>

Displays the modal dialog

Your browser:
Invoker commands

Controls the dialog with buttons

Your browser:
@starting-style

Animates the initial appearance

Your browser:
transition-behavior

Animates closing

Your browser:
<dialog closedby>

Controls how the dialog closes

Your browser:
:has()

Locks page scrolling while open

Your browser:
::backdrop

Styles the video dialog backdrop

Your browser:

Preview

Click the poster or focus it with Tab and press Enter. Close with Esc, the backdrop or the button.

Installation

npx shadcn@latest add @gooseui/video-dialog
pnpm dlx shadcn@latest add @gooseui/video-dialog
yarn dlx shadcn@latest add @gooseui/video-dialog
bunx --bun shadcn@latest add @gooseui/video-dialog

Usage

import { VideoDialog } from "@/components/ui/video-dialog"

export default function Example() {
  return (
    <VideoDialog
      src="/videos/walkthrough.mp4"
      poster="/videos/walkthrough-poster.jpg"
      title="Product walkthrough"
      className="max-w-xl"
    />
  )
}

Examples

Hero block

className styles the preview: aspect ratio, radius, shadow. The player keeps its own 16:9 frame.

Listen to the sea

Twelve seconds of surf with sound. Click the preview to open the player.

<div className="grid items-center gap-6 sm:grid-cols-2">
  <div>
    <h3 className="text-2xl font-semibold">See it in two minutes</h3>
    <p className="text-muted-foreground">A short tour of the editor.</p>
  </div>
  <VideoDialog
    src="/videos/walkthrough.mp4"
    poster="/videos/walkthrough-poster.jpg"
    labels={{ play: "Play the walkthrough", close: "Close video" }}
    className="aspect-[4/3] rounded-2xl shadow-lg"
  />
</div>

Open state events

onOpenChange reports opening and closing. It works when VideoDialog is rendered from a client component. restartOnOpen plays from the start every time.

<VideoDialog
  src="/videos/walkthrough.mp4"
  poster="/videos/walkthrough-poster.jpg"
  restartOnOpen
  onOpenChange={(open) => console.log(open ? "opened" : "closed")}
/>

Props

PropTypeDefaultDescription
srcstring-Video URL for the player
posterstring-Poster for the preview and the player
titlestring"Video"Dialog title for screen readers, visually hidden
labels{ play?: string; close?: string }-Accessible names of the preview and close buttons
restartOnOpenbooleanfalsePlay from the beginning on every open
onOpenChange(open: boolean) => void-Called when the dialog opens or closes (client components only)
dialogClassNamestring-Classes for the player frame in the dialog
classNamestring-Classes for the preview button

Features

  • Opens without JavaScript: native <dialog> with invoker commands, the close button is a <form method="dialog">
  • Sound on Safari: the video is already in the page, so play() runs inside the click
  • Muted fallback: if the browser still blocks sound, the video plays muted and controls stay available
  • No preloading: preload="none": the video does not download until the dialog is opened
  • Accessible modal: native focus trap, Esc, the page behind is inert, focus returns to the preview