Skip to content
SENVENLI UI

Dialog

A modal window for a focused task, with a title, body and footer actions, in small to full-screen sizes.
A focused task
import { Dialog, DialogTrigger } from "@senvenli/react/overlay";

Examples

Submitting a form

The primary action submits the form by its id, so Enter in a field works too.

Sizes

Small by default; medium, large and xlarge for wider content.

Full screen

For a long task: the header and footer stay put, Back and Continue spread apart.

Guidelines

When to use it

  • A short task that needs focus without leaving the page: edit, create, confirm details.

Use something else when

  • The task needs a side panel next to the page. Drawer
  • The user must confirm or cancel one action. Alert dialog

Do and avoid

  • One primary action; the secondary action closes.
  • Use fullscreen for long tasks like a signup, xlarge for two- or three-column forms.

Accessibility

Keyboard

KeysWhat happens
EscCloses the dialog.
TabMoves focus inside the dialog only.

Built in

  • Focus moves to the first field and returns to the opener on close.
  • Named by its title, described by its description.

You provide

  • A title that says what the task is.

API reference

Dialog

isOpen
boolean

Open without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put onOpenChange on the trigger instead: the trigger owns the state there.

defaultOpen
boolean
onOpenChange
(isOpen: boolean) => void
titleRequired
React.ReactNode
description
React.ReactNode

One short line under the title: what the dialog is about. When given, the dialog is described by it (aria-describedby); without it (or with "", false, null) nothing is rendered.

childrenRequired
React.ReactNode
primaryAction
DialogAction
secondaryAction
DialogSecondaryAction

"Cancel" by default, closing the dialog; pass a label or a handler to change it. isDisabled blocks it, e.g. while the primary action runs; iconBefore / iconAfter add a decorative icon. null leaves it out: a full-screen dialog whose steps carry their own buttons, or a locked completion view, has no secondary action, and with no primaryAction either it has no footer at all (the body then takes the bottom padding, and on fullscreen reaches down to the home indicator). With null and a danger primary there is no safe button to focus first, so focus goes to the body's first field (as for any other dialog), or to the dialog itself when the body has none. data-* keys reach the button.

footer
React.ReactNode

The footer's content, in place of primaryAction and secondaryAction: a checkbox beside the buttons, three actions, a link. It sits in the same footer (spacing, footerLayout, the notch and home-indicator insets); close from it with useDialogClose(). As Drawer's footer.

isCloseButtonHidden
boolean

Leaves out the close button in the header, and does nothing else: Esc and a press outside still follow isDismissable. A locked view the user must not dismiss before the flow ends, such as a completion step, sets both: isCloseButtonHidden and isDismissable={false}. It then closes only when the app closes it (isOpen/onOpenChange, or an action whose handler does) or through the secondary action, when there is one; a locked dialog inside a DialogTrigger has no close handle, so control it with isOpen. Focus stays trapped inside and the title still names the dialog. Give it a way on (a primaryAction or a control in the body): with the close button hidden and nothing a keyboard can reach inside, the dialog warns in development (with isDismissable Esc still closes it, but a touch user on fullscreen has no press outside).

initialFocusRef
RefObject<HTMLElement | null>

The element that takes focus when the dialog opens, in place of the DS rule (the first field, or the secondary action before a danger primary). Pass a ref to an element inside the dialog. Left out, or empty when the dialog opens, the rule applies as before.

The ref keeps focus only if, once the dialog calls its focus(), focus is on that element or inside it; otherwise the rule applies after all. So a ref to an element that cannot take focus (a container without a tabIndex, a hidden title) falls through to the rule, and so does a ref whose own focus handler moves focus to an element outside it: the rule then moves focus again, to the safe action or the first field (with neither, focus stays where the handler put it). A handler that moves focus to an element inside the ref keeps it there. To open on a container, give it tabIndex={-1}; to open on another element, pass that element's ref.

returnFocusRef
RefObject<HTMLElement | null>

Where focus goes when the dialog closes, in place of the element that opened it (the trigger): the next step's heading, or a control that stays when the trigger is gone. Read when the dialog closes, so it may point at an element mounted by then. If the app has already moved focus elsewhere on close, it stays there; if the ref is empty, focus returns to the trigger as before.

titleRef
React.Ref<HTMLHeadingElement>

A ref to the title's heading, for an app that puts focus on the title: on open (a completion view, "Password saved"), or when the dialog's content moves to its next step. Given, the heading takes tabIndex={-1}: focusable from code (titleRef.current.focus()), never a Tab stop, and a pointer press on it focuses it. It stays the dialog's heading (role heading, level 2) and its name (aria-labelledby), so a screen reader reads "heading" with the title when focus lands on it.

To open on the title, pass the same ref as initialFocusRef (initialFocusRef={titleRef}): that ref comes first on open, before the first field and the safe secondary action, as for any other element. The title shows the DS focus ring only for keyboard focus (:focus-visible), never for a pointer user's; focus on close returns as before (returnFocusRef, or the trigger). Left out, the heading renders exactly as before.

A hidden title (isTitleHidden, fullscreen) is never a focus target: it is sr-only, so focus on it would show no indicator. With isTitleHidden the ref still holds the heading, but it takes no tabIndex and no focus ring, so titleRef.current.focus() does nothing and initialFocusRef={titleRef} falls through to the dialog's own rule (the first field, or the safe secondary action). To land on something there, aim at a visible element instead: the first field (the default), or a visible heading or control in the body via initialFocusRef.

partData
Partial<Record<"header" | "title" | "body" | "footer" | "close", DataAttributes>>

data-* attributes for the dialog's parts: header, title, body, footer and the close button. The dialog itself (role="dialog", data-slot="dialog") takes the data-* props given to Dialog (data-testid="set-password"); the actions take theirs on primaryAction / secondaryAction. The footer's data-layout (spread) is the DS's own, like data-slot: partData.footer cannot set it.

size
"fullscreen" | OverlaySize | "xlarge"

small (default, 440px), medium (600px) or large (800px); xlarge (1152px) for a form in two or three columns over the page it edits, such as an order edit; or fullscreen for a long task that needs the whole screen, such as a signup: it fills the viewport at every width, slides up as a sheet on phones (below 640px) and fades in above. The header (title, close) and the footer (actions) stay put, clear of the notch and the home indicator, while the body scrolls between them. Below its width every size but fullscreen takes the viewport less 24px a side, and its body scrolls inside 100dvh less 48px. Focus, Esc and naming are the same at every size.

isDismissable
boolean

Scrim click and Esc close it (default). Off for destructive flows with typed input. A fullscreen dialog has no scrim, so a press outside it (a toast or banner layered above) never closes it; there this prop controls Esc only. It is independent of isCloseButtonHidden: a locked view sets both, isCloseButtonHidden and isDismissable={false}; a locked dialog inside a DialogTrigger has no close handle, so control it with isOpen.

footerLayout
"end" | "spread"

fullscreen only. How the footer places its actions: end (default) groups them at the inline end; spread puts the secondary action at the inline start and the primary at the inline end ("Back" … "Continue"), mirrored in RTL. A lone primary action stays at the end; a lone secondary action (no primaryAction) sits at the inline start.

headerLeading
React.ReactNode

fullscreen only. Shown before the title in the header, such as the product's logo. The title then keeps to one line and truncates with an ellipsis (its full text is still the dialog's name); the close button keeps its place at the inline end.

isTitleHidden
boolean

fullscreen only. Hides the title visually, for a frame whose header shows a logo instead; the title stays in the DOM and still names the dialog (aria-labelledby), so title is still required. A description, when given, stays visible. An empty title ("", blank, null, false) would leave the dialog unnamed, and warns in development.

motion
ComponentMotion

auto (follow the device), reduce or none, for this component; the provider's setting otherwise.

DialogTrigger

No props of its own: it takes the behavior props below.

Also takes 3 standard DOM and ARIA attributes (id, aria-label, event handlers…).