Dashral Pro is on the wayGet 30% off at launch

Dashral

Dialog

A modal window that focuses the user on a single task.

$ pnpm dlx shadcn@latest add https://dashral.com/r/dialog.json

Installation

$ pnpm dlx shadcn@latest add https://dashral.com/r/dialog.json

Adds the component, the components it builds on, its npm packages and the theme tokens it uses. Using Dashral often? Add the registry to components.json once:

components.json
{
  "registries": {
    "@dashral": "https://dashral.com/r/{name}.json"
  }
}

Then add components by name:

$ pnpm dlx shadcn@latest add @dashral/dialog

Usage

example.tsx
import { Button } from "@/components/dashral/button"
import { Input } from "@/components/dashral/input"
import { Dialog, DialogClose } from "@/components/dashral/dialog"

<Dialog
  trigger={<Button variant="outline">Edit profile</Button>}
  title="Edit profile"
  description="Your team sees the change at once."
  form={{ action: api.profile.update }}
  footer={
    <>
      <DialogClose asChild>
        <Button variant="outline">Cancel</Button>
      </DialogClose>
      <Button type="submit">Save</Button>
    </>
  }
>
  <Input label="Name" name="name" defaultValue="Olivia Martin" />
</Dialog>

Examples

Confirmation

Hide the close button so the user makes an explicit choice.

Invite people

A form dialog: paste emails, pick a role, send. It shows it's sending, then closes with a toast.

OMLJSDBSBudi Santoso

API reference

Dialog

Also takes every prop of Radix Dialog(opens in a new tab).

PropTypeDefault
triggerReactElement

What opens it. Leave it out to open it with open / onOpenChange.

—
titleReactNode

Required: it names the dialog. Hide it with classNames.title "sr-only" if the design has none.

—
descriptionReactNode

Under the title; it describes the dialog.

—
childrenReactNode

The body.

—
footerReactNode

Buttons at the bottom.

—
formComponentProps<"form">

Makes the body and footer one form, e.g. { onSubmit } or { action }.

—
size"sm" | "md" | "lg" | "xl"

The window's width.

"md"
showCloseButtonboolean

The × in the corner.

true
open / defaultOpen / onOpenChange

Controlled or initial state.

—
classNames{ header, title, description, footer }

Classes for each part.

—
classNamestring

The window's classes.

—

DialogClose

Closes the dialog: wrap a Cancel button in the footer.

Also takes every prop of Radix Dialog(opens in a new tab).

PropTypeDefault
asChildboolean

Render the child element instead (e.g. a Next.js Link), passing these styles and props to it.

false

Keyboard

KeysAction
TaborShift+TabMove between controls; focus stays inside while it's open
EscapeClose and return focus to what opened it

Accessibility

  • role="dialog" with aria-modal, labelled by its title and described by its description.
  • The rest of the page is inert while it's open.

Motion

  • The window springs in from 95% with a soft blur clearing; the backdrop fades in and blurs the page a little. Closing is quicker.