Componentfeedback1.74 KB gzipZero dependencies

Dialog

Accessible modal dialog with focus trap and scale animation.

Preview

Live Preview
Open ↗

Installation

Tokens guide →

Add to your project via CLI (zero dependencies, code you own):

npx bigbullui add dialog

Or install the full npm package:

npm install bigbullui

Usage

tsx12 lines
const [open, setOpen] = useState(false); <Button onClick={() => setOpen(true)}>Open</Button><Dialog open={open} onOpenChange={setOpen}>  <DialogHeader>    <DialogTitle>Title</DialogTitle>    <DialogDescription>Description.</DialogDescription>  </DialogHeader>  <DialogFooter>    <Button onClick={() => setOpen(false)}>Got it</Button>  </DialogFooter></Dialog>

Source code

dialog.tsx + 4 helpers

Zero third-party dependencies (5 local files shown in tabs below).

tsxdialog.tsx219 lines
"use client"; import * as React from "react";import { createPortal } from "react-dom";import { cn } from "./lib/utils";import {  getFocusable,  hideBackgroundSiblings,  lockBodyScroll,  registerEscapeLayer,  trapFocus,} from "./lib/focus-trap";import { useIsMounted } from "./lib/react-compat";import { useControllableState } from "./lib/use-controllable-state"; interface DialogContextValue {  titleId: string;  descriptionId: string;

Props

Interactive Prop Playground

Tweak parsed AST props below to generate ready-to-paste JSX.

tsx3 lines
import { Dialog } from "@/components/ui/dialog"; <Dialog />
PropTypeDescription
openbooleanWhether the dialog is open (controlled).
defaultOpenbooleanInitial open state when uncontrolled. (Default: false)
onOpenChange(open: boolean) => voidCalled when open state should change.
childrenReact.ReactNodeChild elements rendered inside the component.
classNamestringOptional Tailwind or custom CSS classes merged with component styles.
aria-labelstringConfigures aria label.
hideCloseButtonbooleanToggles hide close button. (Default: false)
animatedbooleanDual-mode: false renders instantly with no motion. Default true.