Dialog

This layout keeps the popup fully on screen while allowing its content to scroll.

What a dialog is for

Use a dialog when you need the user to complete a focused task or read something important without navigating away. It opens on top of the page and returns focus back where it started when closed.

Anatomy at a glance

Root, Trigger, Portal, Backdrop, Viewport, Popup, Title, Description, Close. Keep the title short and the first paragraph specific so screen readers announce something meaningful.

Opening and closing

Control it using external state via the `open` and `onOpenChange` props, or let it manage state for you internally.

Keyboard and focus behavior

Focus moves inside the dialog when it opens. Tab and Shift+Tab loop within, and Esc requests close.

Accessible labeling

Set an explicit title and description using the `Dialog.Title` and `Dialog.Description` components.

Backdrop and page scrolling

The backdrop visually separates layers while background content is inert. Don’t rely on dimness alone—keep copy clear and buttons obvious so actions are easy to choose.

Portals and stacking

Dialogs render in a portal so they sit above the `isolation: isolate` app content and avoid local z-index wars.

Viewport overflow

Let long content overflow the bottom edge and reveal as you scroll the page container. Keep generous padding at the top and bottom so the dialog doesn’t feel jammed against the edges.

Nested dialogs and confirmations

If closing a dialog needs confirmation, open a child alert dialog rather than mutating the current one. The parent stays visible behind it; only the topmost layer should feel interactive.

Transitions that respect motion settings

Use small, fast transitions (opacity plus a few pixels of Y translation or scale). Subtle motion helps people notice what changed without slowing them down.

Controlled vs. uncontrolled

Controlled state is best when other parts of the page need to react to open/close. Uncontrolled is fine for local cases where only the dialog matters.

Close affordances

Always offer a visible close button in the corner. Don’t rely only on Esc or the backdrop for pointer outside presses. Touch screen readers and accessibility users benefit from a clear, targetable control to click to close the dialog.

Forms inside dialogs

Keep forms short; longer flows usually deserve a full page. Validate inline, keep button text specific (“Create project”), and disable destructive actions until the input is valid.

Content guidelines

Lead with the outcome (“Rename project?”) and follow with one or two short, concrete sentences. Avoid long prose; link out for details instead.

SSR and hydration notes

Because dialogs render in a portal, make sure your portal container exists on the client.

Mobile ergonomics

Use larger touch targets and keep the close button reachable with the thumb. Avoid full-screen modals unless the task truly needs a whole screen.

Theming and density

Match spacing and corner radius to your system. Use a slightly denser layout than pages so the dialog feels purpose-built, not like a mini web page.

Internationalization

Plan for longer text. Buttons can grow to two lines; titles should wrap gracefully. Keep destructive terms consistent across locales.

Performance

The content of the dialog is in the first render of the page. If it is slow to render, put it in a `<Suspense>`: the page sends a fallback first and the content after, so the page does not wait for it. With `lazy`, the browser loads the content when the fallback comes into view.

When a popover is better

If the content is a small hint or a few quick actions anchored to a control, use a popover or menu instead of a dialog. Dialogs interrupt on purpose—use that sparingly.

Follow-up and cleanup

After a successful action, close the dialog and show confirmation in context (toast, inline message, or updated UI) so people can see the result of what they just did.