import { Button } from "@senvenli/react/action";
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { Dialog, DialogTrigger } from "@senvenli/react/overlay";
import { useState } from "react";
export default function Example() {
const [isOpen, setIsOpen] = useState(false);
return (
<DialogTrigger isOpen={isOpen} onOpenChange={setIsOpen}>
<Button>Edit profile</Button>
<Dialog
title="Edit profile"
description="Your name is shown to your team."
primaryAction={{ label: "Save changes", onPress: () => setIsOpen(false) }}
>
<Stack space="space-200">
<Input label="Full name" defaultValue="Ada Lovelace" />
<Input label="Email" type="email" defaultValue="ada@example.com" />
</Stack>
</Dialog>
</DialogTrigger>
);
}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.import { Button } from "@senvenli/react/action";
import { Form, Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { Dialog, DialogTrigger, toast } from "@senvenli/react/overlay";
import { Select } from "@senvenli/react/selection";
import { useId, useState } from "react";
export default function Example() {
const [isOpen, setIsOpen] = useState(false);
const formId = useId();
return (
<DialogTrigger isOpen={isOpen} onOpenChange={setIsOpen}>
<Button iconBefore="user-plus">Invite member</Button>
<Dialog title="Invite a team member" primaryAction={{ label: "Send invite", form: formId }}>
<Form
id={formId}
onSubmit={(event) => {
event.preventDefault();
const email = new FormData(event.currentTarget).get("email");
setIsOpen(false);
toast.success("Invite sent", { description: String(email) });
}}
>
<Stack space="space-200">
<Input label="Email" name="email" type="email" isRequired />
<Select
label="Role"
name="role"
defaultSelectedKey="member"
items={[
{ id: "member", label: "Member" },
{ id: "admin", label: "Admin" },
]}
/>
</Stack>
</Form>
</Dialog>
</DialogTrigger>
);
}Sizes
Small by default; medium, large and xlarge for wider content.import { Button } from "@senvenli/react/action";
import { Text } from "@senvenli/react/display";
import { Stack } from "@senvenli/react/layout";
import { Dialog, DialogTrigger } from "@senvenli/react/overlay";
const SIZES = [
{ size: "small", width: "440px" },
{ size: "medium", width: "600px" },
{ size: "large", width: "800px" },
{ size: "xlarge", width: "1152px" },
] as const;
export default function Example() {
return (
<Stack direction="horizontal" space="space-100">
{SIZES.map(({ size, width }) => (
<DialogTrigger key={size}>
<Button>{size}</Button>
<Dialog size={size} title="Order ORD-1040" secondaryAction={{ label: "Close" }}>
<Text>
This dialog is {size}: up to {width} wide, or the viewport less its margins.
</Text>
</Dialog>
</DialogTrigger>
))}
</Stack>
);
}Full screen
For a long task: the header and footer stay put, Back and Continue spread apart.import { Button } from "@senvenli/react/action";
import { Input } from "@senvenli/react/form";
import { Stack } from "@senvenli/react/layout";
import { Dialog, DialogTrigger } from "@senvenli/react/overlay";
import { useState } from "react";
export default function Example() {
const [isOpen, setIsOpen] = useState(false);
const close = () => setIsOpen(false);
return (
<DialogTrigger isOpen={isOpen} onOpenChange={setIsOpen}>
<Button>Create workspace</Button>
<Dialog
size="fullscreen"
footerLayout="spread"
title="Create a workspace"
description="Step 1 of 3 · Name and address"
secondaryAction={{ label: "Back", iconBefore: "arrow-left", onPress: close }}
primaryAction={{ label: "Continue", iconAfter: "arrow-right", onPress: close }}
>
<div className="mx-auto w-full max-w-120">
<Stack space="space-200">
<Input label="Workspace name" defaultValue="Analytical Engines" />
<Input label="Web address" defaultValue="analytical-engines" description="Lowercase letters, numbers and hyphens." />
</Stack>
</div>
</Dialog>
</DialogTrigger>
);
}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
| Keys | What happens |
|---|---|
| Esc | Closes the dialog. |
| Tab | Moves 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
| Prop | Type | Default | Description |
|---|---|---|---|
isOpen | boolean | – | Open without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put |
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 ( |
childrenRequired | React.ReactNode | – | |
primaryAction | DialogAction | – | |
secondaryAction | DialogSecondaryAction | – | "Cancel" by default, closing the dialog; pass a label or a handler to change it. |
footer | React.ReactNode | – | The footer's content, in place of |
isCloseButtonHidden | boolean | – | Leaves out the close button in the header, and does nothing else: Esc and a press outside still follow |
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 The ref keeps focus only if, once the dialog calls its |
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 To open on the title, pass the same ref as A hidden title ( |
partData | Partial<Record<"header" | "title" | "body" | "footer" | "close", DataAttributes>> | – |
|
size | "fullscreen" | OverlaySize | "xlarge" | – |
|
isDismissable | boolean | – | Scrim click and Esc close it (default). Off for destructive flows with typed input. A |
footerLayout | "end" | "spread" | – |
|
headerLeading | React.ReactNode | – |
|
isTitleHidden | boolean | – |
|
motion | ComponentMotion | – |
|
isOpenbooleanOpen without a DialogTrigger (a URL, a row click). Inside a DialogTrigger, put
onOpenChangeon the trigger instead: the trigger owns the state there.defaultOpenbooleanonOpenChange(isOpen: boolean) => voidtitleRequiredReact.ReactNodedescriptionReact.ReactNodeOne 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.childrenRequiredReact.ReactNodeprimaryActionDialogActionsecondaryActionDialogSecondaryAction"Cancel" by default, closing the dialog; pass a label or a handler to change it.
isDisabledblocks it, e.g. while the primary action runs;iconBefore/iconAfteradd a decorative icon.nullleaves it out: a full-screen dialog whose steps carry their own buttons, or a locked completion view, has no secondary action, and with noprimaryActioneither it has no footer at all (the body then takes the bottom padding, and onfullscreenreaches down to the home indicator). Withnulland adangerprimary 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.footerReact.ReactNodeThe footer's content, in place of
primaryActionandsecondaryAction: 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 withuseDialogClose(). As Drawer'sfooter.isCloseButtonHiddenbooleanLeaves 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:isCloseButtonHiddenandisDismissable={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 withisOpen. Focus stays trapped inside and the title still names the dialog. Give it a way on (aprimaryActionor a control in the body): with the close button hidden and nothing a keyboard can reach inside, the dialog warns in development (withisDismissableEsc still closes it, but a touch user onfullscreenhas no press outside).initialFocusRefRefObject<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
dangerprimary). 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 atabIndex, 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 ittabIndex={-1}; to open on another element, pass that element's ref.returnFocusRefRefObject<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.
titleRefReact.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 (roleheading, 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 issr-only, so focus on it would show no indicator. WithisTitleHiddenthe ref still holds the heading, but it takes notabIndexand no focus ring, sotitleRef.current.focus()does nothing andinitialFocusRef={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 viainitialFocusRef.partDataPartial<Record<"header" | "title" | "body" | "footer" | "close", DataAttributes>>data-*attributes for the dialog's parts:header,title,body,footerand theclosebutton. The dialog itself (role="dialog",data-slot="dialog") takes thedata-*props given to Dialog (data-testid="set-password"); the actions take theirs onprimaryAction/secondaryAction. The footer'sdata-layout(spread) is the DS's own, likedata-slot:partData.footercannot set it.size"fullscreen" | OverlaySize | "xlarge"small(default, 440px),medium(600px) orlarge(800px);xlarge(1152px) for a form in two or three columns over the page it edits, such as an order edit; orfullscreenfor 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 butfullscreentakes the viewport less 24px a side, and its body scrolls inside 100dvh less 48px. Focus, Esc and naming are the same at every size.isDismissablebooleanScrim click and Esc close it (default). Off for destructive flows with typed input. A
fullscreendialog 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 ofisCloseButtonHidden: a locked view sets both,isCloseButtonHiddenandisDismissable={false}; a locked dialog inside a DialogTrigger has no close handle, so control it withisOpen.footerLayout"end" | "spread"fullscreenonly. How the footer places its actions:end(default) groups them at the inline end;spreadputs 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 (noprimaryAction) sits at the inline start.headerLeadingReact.ReactNodefullscreenonly. 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.isTitleHiddenbooleanfullscreenonly. 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), sotitleis still required. A description, when given, stays visible. An empty title ("", blank,null,false) would leave the dialog unnamed, and warns in development.motionComponentMotionauto(follow the device),reduceornone, for this component; the provider's setting otherwise.