Glass Modal Dialog for React
A strong-glass React modal dialog that springs in with Motion, with focus trapping, Escape to close and focus return handled by Base UI.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/dialog.jsonProject members
Maya and Jonas are not on the team yet.
DialogDialogCloseDialogTitleDialogFooterDialogHeader- +7 more
- +4 more
Edit profile
import { Button } from "@/components/sheenui/button/button";
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/sheenui/dialog/dialog";
import { Input } from "@/components/sheenui/input/input";
// Package build (after the first npm release, or a packed tarball): import { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, Input } from "@sheenui/theme";
// This example also uses button, input: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/input.json
export function Example() {
return (
<Dialog>
<DialogTrigger render={<Button />}>Edit profile</DialogTrigger>
<DialogContent>
<DialogHeader>
<DialogTitle>Edit profile</DialogTitle>
<DialogDescription>Changes are saved to your account.</DialogDescription>
</DialogHeader>
<Input label="Name" defaultValue="Ada Lovelace" />
<DialogFooter>
<DialogClose render={<Button variant="ghost" />}>Cancel</DialogClose>
<DialogClose render={<Button />}>Save</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
}Files to copy
5 folders · 9 files · 4 packages
- From
theme/src/ components/dialog/components/drawer/parts/sheet.tsxhooks/{use-latest.ts, use-media-query.ts}lib/{cn.ts, form.ts, modal-flag.ts, modal-tab-trap.ts, popup-motion.ts, state-light.tsx}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/dialog.jsonRegistry item: dialog. The styles need the Tailwind v4 glass UI setup.- The examples also use
components/button/components/input/components/spinner/components/toast/hooks/{use-direction.ts, use-magnetic.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/field-size.ts
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/input.json https://lokendra-builds.github.io/sheenui/r/toast.json- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Controlled, with a form
Open state lives in your component, so any button (or code) can open it and a successful submit can close it.
import { useState } from "react";
import { Button } from "@/components/sheenui/button/button";
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/sheenui/dialog/dialog";
import { Input } from "@/components/sheenui/input/input";
import { useToast } from "@/components/sheenui/toast/toast";
// Package build (after the first npm release, or a packed tarball): import { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, Input, useToast } from "@sheenui/theme";
// This example also uses button, input, toast: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json https://lokendra-builds.github.io/sheenui/r/input.json https://lokendra-builds.github.io/sheenui/r/toast.json
export function Example() {
const [open, setOpen] = useState(false);
const toast = useToast();
return (
<>
<Button onClick={() => setOpen(true)}>Invite a teammate</Button>
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>Invite a teammate</DialogTitle>
<DialogDescription>They get an email with a link to join the workspace.</DialogDescription>
</DialogHeader>
<form
id="invite-form"
onSubmit={(event) => {
event.preventDefault();
setOpen(false);
toast.success("Invitation sent");
}}
>
<Input label="Email" type="email" required placeholder="name@example.com" />
</form>
<DialogFooter>
<DialogClose render={<Button variant="ghost" />}>Cancel</DialogClose>
<Button type="submit" form="invite-form">Send invite</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
}Bottom sheet on phones
mobile='sheet' presents the dialog as a bottom sheet under 640px wide: full width, a drag handle you can swipe down, content scrolling inside a 85dvh cap, safe-area padding. Escape, the close button and focus return work as before. The default, 'popup', keeps the centred window. Press “Preview on a phone” to try it on a desktop screen (or narrow the window).
import { Button } from "@/components/sheenui/button/button";
import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@/components/sheenui/dialog/dialog";
// Package build (after the first npm release, or a packed tarball): import { Button, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from "@sheenui/theme";
// This example also uses button: npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/button.json
export function Example() {
return (
<Dialog mobile="sheet">
<DialogTrigger render={<Button>Share</Button>} />
<DialogContent>
<DialogHeader>
<DialogTitle>Share this file</DialogTitle>
<DialogDescription>Anyone with the link can view it.</DialogDescription>
</DialogHeader>
<DialogFooter>
<DialogClose render={<Button variant="ghost" />}>Done</DialogClose>
</DialogFooter>
</DialogContent>
</Dialog>
);
}Props
DialogContent props
DialogLabels keys and English defaults (1)
Keyboard
Accessibility
- Built on Base UI's Dialog: role="dialog", named by DialogTitle and described by DialogDescription; the page behind is inert while it is open.
- Focus is trapped, starts on the first control (or initialFocus) and returns to the trigger on close.
- Always render a DialogTitle; showClose adds a labeled close button. Under reduced motion the dialog only fades.
All exports on this page
Dialog— Glass dialog: a modal window that blocks the page until the person answers or dismisses it.DialogClose— A button inside the dialog that closes it (a "Cancel" or "Done" action in DialogFooter).DialogContent— The glass window of a Dialog, portalled to the end of the body with a dimmed scrim behind it.DialogDescription— Muted helper text under the title.DialogFooter— Layout wrapper for the dialog's actions: a column on phones (primary action last in the DOM, so it is first on screen) and a right-aligned row from sm up.DialogHeader— Layout wrapper for DialogTitle and DialogDescription.DialogTitle— The dialog's heading.DialogTrigger— The element that opens a Dialog.defaultDialogLabels— English defaults of DialogLabels.
When to use Dialog
- Use Dialog as a glass modal for a short form that blocks the page, such as renaming a project or inviting a teammate, where the person finishes or cancels before going back to the page. Use it as an animated modal in React whenever the content needs the person's full attention.
- Use it for a details view opened from a table row or a card, with DialogTitle and DialogDescription naming and describing it for screen readers.
- Use DialogFooter with DialogClose for Cancel and Save actions, and keep the corner close button on with showClose unless the footer already offers a clear exit.
- Skip it when the person must answer a destructive question, where AlertDialog fits better, or when the content is a side panel you want next to the page, where Drawer fits better.
- Pair it with Button through the render prop on DialogTrigger, Input and Field for the form inside, and Toast to confirm the result after the dialog closes.
Frequently asked questions
Related pages
Guides that cover it
67 components pages in all: browse them on All components.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .