Skip to content
Pixelbits
Docs / Dialog and Sheet
Overlays

Dialog and Sheet

A modal dialog on the native <dialog> element: the page behind becomes inert, focus is trapped and returns to the trigger, Escape closes it, and it sits in the top layer above everything. Page scrolling is locked while it is open.

Installation

npm: import
import { Dialog, Sheet, DialogClose } from "pixelbits/dialog";
shadcn: copy the source
npx shadcn add https://pixelbits.ali-moradi-develop.com/r/dialog.json

API

<Dialog>

A modal dialog on the native <dialog> element: the page behind becomes inert, focus is trapped and returns to the trigger, Escape closes it, and it sits in the top layer above everything. Page scrolling is locked while it is open.

Example
<Dialog
  trigger={<Button variant="primary">Publish</Button>}
  title="Publish component?"
  description="It will be added to the public registry."
  footer={<><DialogClose asChild><Button variant="ghost">Cancel</Button></DialogClose><Button variant="primary" onClick={publish}>Publish</Button></>}
/>
PropTypeDefaultDescription
openboolean—

Whether it is open (controlled).

defaultOpenbooleanfalse

Open on first render (uncontrolled).

onOpenChange(open: boolean) => void—

Called when it opens or closes (trigger, close button, Escape, backdrop).

triggerReactElement—

An element that opens it on click, usually a Button. It gets aria-haspopup="dialog" and the dialog returns focus to it on close.

titleReactNode—

Heading, linked with aria-labelledby. Strongly recommended.

descriptionReactNode—

Text under the heading, linked with aria-describedby.

footerReactNode—

Actions shown at the bottom, usually Buttons and a DialogClose.

dismissiblebooleantrue

Close when the backdrop is clicked. Escape always closes.

closeButtonbooleantrue

Show the × button in the corner.

childrenReactNode—

The body.

Also accepts every prop of Omit<DialogHTMLAttributes<HTMLDialogElement>, "open" | "title">.

<Sheet>

A panel that slides in from an edge: filters, navigation, details. Same behavior and props as Dialog (it is a modal <dialog> too).

Example
<Sheet side="end" trigger={<Button>Filters</Button>} title="Filters">…</Sheet>
PropTypeDefaultDescription
side"start" | "end" | "top" | "bottom""end"

The edge it slides in from. "start"/"end" follow the text direction (left/right in LTR, right/left in RTL).

Also accepts every prop of DialogProps.

<DialogClose>

Closes the surrounding Dialog or Sheet when clicked.

Example
<DialogClose asChild><Button variant="ghost">Cancel</Button></DialogClose>
PropTypeDefaultDescription
asChildbooleanfalse

Render the child element (for example a Button) as the close control instead of a plain button.

children*ReactNode—

The label or the element to use.

classNamestring—

Extra classes, for the button or merged into the child with asChild.