Skip to Content
Neshel-UI
Components

Dialog

A modal dialog composed of trigger, content, header, body, footer, title, description and close parts.

Client component ("use client")

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.tsx
import {
  Dialog,
  DialogBody,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@neshel-ui/components";

Usage

Preview: dialog-basic
Preview theme
dialog-basic.tsx
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

DialogContentProps
PropTypeDefaultDescription
closeLabelstring"Close"Accessible name of the close button (default "Close").
containerHTMLElement | nulldocument.bodyPortal target (default document.body, wrapped with the trigger's theme).
refRef<HTMLDivElement>——
showClosebooleantrueRender a close button with an accessible label (default true).
sizeDialogSize"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

DialogTriggerProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DialogCloseProps

DialogCloseProps
PropTypeDefaultDescription
refRef<HTMLButtonElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DialogTitleProps

DialogTitleProps
PropTypeDefaultDescription
refRef<HTMLHeadingElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DialogDescriptionProps

DialogDescriptionProps
PropTypeDefaultDescription
refRef<HTMLParagraphElement>——

Also accepts the props of: @radix-ui/react-primitive, React DOM attributes.

DialogPartProps

DialogPartProps
PropTypeDefaultDescription
refRef<HTMLDivElement>——

Also accepts the props of: React DOM attributes.

PartRenders
DialogState root (no DOM)
DialogTriggerButton that opens the dialog (asChild for your Button)
DialogContentPortal, backdrop and the dialog panel, with a close button
DialogHeader / DialogBody / DialogFooterStructural divs
DialogTitleThe accessible name (h2)
DialogDescriptionThe accessible description (p)
DialogCloseButton 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.

Preview: dialog-controlled
Preview theme
open: false
dialog-controlled.tsx
"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, pass aria-describedby={undefined} on DialogContent.
  • 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-theme across the portal.

Keyboard

KeyAction
Tab / Shift+TabMove focus within the dialog (trapped)
EscapeClose 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 styled div instead of it.
  • Submitting a form and expecting the dialog to close by itself: control open.
  • Using a Dialog for a destructive confirmation — see AlertDialog.
Edit on GitHub

On this page