cnippet/ui
  1. ui
  2. overlays
  3. dialog

overlays

Dialog

A popup that opens on top of the entire page. Built with Base UI and Tailwind CSS. Copy-paste ready.

API Reference

Installation

Usage

DialogFooter Variant

The DialogFooter component supports a variant prop to control its styling:

  • default (default): Includes a border-top, background color, and padding
  • bare: Removes the border and background for a minimal appearance

DialogPanel Scrolling

The DialogPanel component automatically wraps its content in a ScrollArea component. This means that if the content exceeds the dialog's maximum height, it will become scrollable automatically. The scrollbar will appear when needed, providing a smooth scrolling experience.

Anatomy

Good to know

  • DialogContent and DialogOverlay are aliases of DialogPopup and DialogBackdrop. Prefer the Popup names.
  • DialogPopup already renders the portal, backdrop and a close (X) button. Don't add them yourself. Hide the X with showCloseButton={false}.
  • DialogTrigger and DialogClose are unstyled. Style them with render={<Button />}. There is no asChild.
  • Put long content in DialogPanel. It scrolls when the dialog reaches the screen height, while the header and footer stay in place.
  • On small screens the dialog becomes a bottom sheet. Turn this off with bottomStickOnMobile={false}.
  • The state props are open, defaultOpen and onOpenChange. To close after saving, control open yourself.
  • Always include a DialogTitle. It gives the dialog its accessible name.
  • For destructive confirmations, use AlertDialog. Clicking outside it doesn't close it.

API Reference

Dialog

Root provider. Wraps Base UI Dialog.Root.

DialogTrigger

Button that opens the dialog.

DialogClose

Button that closes the dialog.

DialogPopup

The modal popup. Also exported as DialogContent.

DialogHeader

Flex column container for DialogTitle and DialogDescription.

DialogFooter

Action button row at the bottom of the dialog.

DialogTitle

Accessible title element.

DialogDescription

Accessible description providing additional context.

DialogPanel

Scrollable content region. Automatically wrapped in ScrollArea.

Examples

Open from a Menu

Demonstrates triggering a Dialog from a MenuItem, allowing dialogs to be opened as secondary actions from dropdowns.

Uses DialogFooter variant="bare" to remove the border and background from the footer for a minimal, form-like appearance.

With Scroll

Tall content inside DialogPanel becomes automatically scrollable via the built-in ScrollArea wrapper.

Nested Dialogs

Opens a second dialog from within an already-open dialog, demonstrating stacked overlay behavior and layered focus trapping.

With Destructive Action

A confirmation dialog with a red destructive button for irreversible actions like permanently deleting content.

A settings dialog with toggle switches for managing cookie consent categories such as analytics and marketing.

Session Expired

A blocking dialog notifying the user their session has timed out, with a single "Sign in again" action button.

Edit Profile

A dialog form for updating a user profile that includes an avatar upload area and editable input fields.

Invite Team Members

A dialog for inviting users by email with a role selector and a scrollable list of pending invites.

Share Document

A share dialog with a copyable link field, a one-click copy button that switches to a checkmark on success, and permission-level selector tiles.

Two-Factor Authentication Setup

A 2FA setup dialog displaying a simulated QR code placeholder and a six-digit code entry — verifying the code locks the input and shows a success state.

Subscription Cancellation

A cancellation dialog prompting the user to choose a reason before confirming — the destructive action stays disabled until a reason is selected.

API Key Generation

Generates a new secret API key with mask/reveal toggle, one-click copy with confirmation feedback, and a regenerate button — all within a secure disclosure flow.

Product Feedback Rating

A star-rating feedback form for multiple product aspects (Ease of use, Performance, Design, Support) with an optional comment textarea — Submit stays disabled until every category is rated.