Dialog
A modal dialog composed of trigger, content, header, body, footer, title, description and close parts.
Purpose
Dialog shows a modal window for a focused task — editing, confirming details, settings. The rest of
the page becomes inert while it is open.
Import
import {
Dialog,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
} from "@neshel-ui/components";Usage
import {
Button,
Dialog,
DialogBody,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
Input,
Label,
} from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
export default function DialogBasic() {
return (
<Dialog>
<DialogTrigger asChild>
<Button>Edit profile</Button>
</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>Update your account information.</DialogDescription>
</DialogHeader>
<DialogBody>
<Stack space="2">
<Label htmlFor="dialog-name">Name</Label>
<Input id="dialog-name" defaultValue="Ana" />
</Stack>
</DialogBody>
<DialogFooter>
<DialogClose asChild>
<Button variant="outline">Cancel</Button>
</DialogClose>
<DialogClose asChild>
<Button>Save</Button>
</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
}API
DialogProps
Also accepts the props of: @radix-ui/react-dialog.
DialogContentProps
| Prop | Type | Default | Description |
|---|---|---|---|
| closeLabel | string | "Close" | Accessible name of the close button (default "Close"). |
| container | HTMLElement | null | document.body | Portal target (default document.body, wrapped with the trigger's theme). |
| ref | Ref<HTMLDivElement> | — | — |
| showClose | boolean | true | Render a close button with an accessible label (default true). |
| size | DialogSize | "md" | Maximum width; "full" fills the viewport (default "md"). |
Also accepts the props of: @radix-ui/react-dialog, @radix-ui/react-dismissable-layer, @radix-ui/react-primitive, React DOM attributes.
DialogSize
type DialogSize = "sm" | "md" | "lg" | "xl" | "full"DialogTriggerProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
DialogCloseProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLButtonElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
DialogTitleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLHeadingElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
DialogDescriptionProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLParagraphElement> | — | — |
Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.
DialogPartProps
| Prop | Type | Default | Description |
|---|---|---|---|
| ref | Ref<HTMLDivElement> | — | — |
Also accepts the props of: React DOM attributes.
| Part | Renders |
|---|---|
Dialog | State root (no DOM) |
DialogTrigger | Button that opens the dialog (asChild for your Button) |
DialogContent | Portal, backdrop and the dialog panel, with a close button |
DialogHeader / DialogBody / DialogFooter | Structural divs |
DialogTitle | The accessible name (h2) |
DialogDescription | The accessible description (p) |
DialogClose | Button that closes the dialog (asChild) |
DialogContent sizes: sm, md (default), lg, xl, full. showClose={false} removes the
built-in close button; closeLabel renames it.
Controlled and uncontrolled
Uncontrolled: the trigger opens it and closes close it. Controlled: own open and onOpenChange —
for example to close after a successful submit.
"use client";
import { Button, Dialog, DialogContent, DialogFooter, DialogTitle } from "@neshel-ui/components";
import { Inline } from "@neshel-ui/layout";
import { Text } from "@neshel-ui/typography";
import { useState } from "react";
export default function DialogControlled() {
const [open, setOpen] = useState(false);
return (
<Inline space="3" align="center">
<Button onClick={() => setOpen(true)}>Open (controlled)</Button>
<Text tone="muted">open: {String(open)}</Text>
<Dialog open={open} onOpenChange={setOpen}>
{/* No description: opt out of aria-describedby explicitly. */}
<DialogContent size="sm" aria-describedby={undefined}>
<DialogTitle>Controlled dialog</DialogTitle>
<DialogFooter>
<Button onClick={() => setOpen(false)}>Close</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</Inline>
);
}Composition
Triggers and closes support asChild (use your Button). Dialogs can be nested; Escape closes the
innermost one. Selection popups inside a dialog render inside it.
Accessibility
- Every dialog needs a
DialogTitle(a development warning reports a missing one). Without a description, passaria-describedby={undefined}onDialogContent. - Focus moves to the first focusable element, is trapped, and returns to the trigger on close (for a controlled dialog, to the element that opened it).
- The content copies the trigger's
data-neshel-themeacross the portal.
Keyboard
| Key | Action |
|---|---|
| Tab / Shift+Tab | Move focus within the dialog (trapped) |
| Escape | Close the dialog (innermost layer only) |
Styling
The panel uses --neshel-surface / --neshel-surface-foreground, the backdrop
--neshel-overlay-backdrop, the layer --neshel-z-overlay. Inline custom properties on an ancestor
need container — see portal containers.
Common mistakes
- No
DialogTitle, or a visually styleddivinstead of it. - Submitting a form and expecting the dialog to close by itself: control
open. - Using a Dialog for a destructive confirmation — see AlertDialog.