Dialog
A dialog asks for a decision or a short input in a window over the page, which stays dimmed behind it.
When to use
Section titled “When to use”- Use it for a short form or a choice that needs the whole attention, such as renaming a release.
- Use an Alert Dialog to confirm an action that can’t be undone.
- Use a Toast to confirm something that already happened.
- Don’t put long flows in a dialog; use a page.
Do and don’t
Section titled “Do and don’t”Anatomy
Section titled “Anatomy”- 1Overlay
- 2Title
- 3Body
- 4Actions, primary last
Title, description, optional content, then actions in the footer. The window sits on popover with a border, radius-xl (16px) and shadow-lg. The page behind it is dimmed with the overlay token.
Variants
Section titled “Variants”There is one style. Put the main action last in the footer.
| React | Vue | Flutter | Type | Default | Use |
|---|---|---|---|---|---|
open / defaultOpen |
v-model:open / default-open |
showShadDialog |
boolean | false |
Whether it is open. |
onOpenChange |
@update:open |
return value of showShadDialog |
function | none | Runs when it opens or closes. |
DialogTrigger render |
DialogTrigger as-child |
onPressed |
element | button | The control that opens it. |
import { useId } from "react"import { Button } from "@/components/ui/button"import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from "@/components/ui/dialog"import { Field, FieldLabel } from "@/components/ui/field"import { Input } from "@/components/ui/input"
export default function DialogDemo() { const id = useId() return ( <Dialog> <DialogTrigger render={<Button variant="outline" />}>Ubah judul</DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>Ubah judul rilis</DialogTitle> <DialogDescription>Judul baru tampil di semua toko musik setelah dikirim ulang.</DialogDescription> </DialogHeader> <Field> <FieldLabel htmlFor={`${id}-title`}>Judul rilis</FieldLabel> <Input id={`${id}-title`} defaultValue="Senja di Kota" /> </Field> <DialogFooter> <DialogClose render={<Button variant="outline" />}>Batal</DialogClose> <DialogClose render={<Button />}>Simpan</DialogClose> </DialogFooter> </DialogContent> </Dialog> )}<script setup lang="ts">import { useId } from "vue"import { Button } from "@/components/ui/button"import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger,} from "@/components/ui/dialog"import { Field, FieldLabel } from "@/components/ui/field"import { Input } from "@/components/ui/input"
const id = useId()</script>
<template> <Dialog> <DialogTrigger as-child> <Button variant="outline">Ubah judul</Button> </DialogTrigger> <DialogContent> <DialogHeader> <DialogTitle>Ubah judul rilis</DialogTitle> <DialogDescription>Judul baru tampil di semua toko musik setelah dikirim ulang.</DialogDescription> </DialogHeader> <Field> <FieldLabel :for="`${id}-title`">Judul rilis</FieldLabel> <Input :id="`${id}-title`" default-value="Senja di Kota" /> </Field> <DialogFooter> <DialogClose as-child><Button variant="outline">Batal</Button></DialogClose> <DialogClose as-child><Button>Simpan</Button></DialogClose> </DialogFooter> </DialogContent> </Dialog></template>import 'package:flutter/widgets.dart';import 'package:shadcn_ui/shadcn_ui.dart';
class DialogDemo extends StatelessWidget { const DialogDemo({super.key});
@override Widget build(BuildContext context) { return ShadButton.outline( child: const Text('Ubah judul'), onPressed: () => showShadDialog( context: context, builder: (context) => ShadDialog( title: const Text('Ubah judul rilis'), description: const Text('Judul baru tampil di semua toko musik setelah dikirim ulang.'), actions: [ ShadButton.outline(child: const Text('Batal'), onPressed: () => Navigator.of(context).pop()), ShadButton(child: const Text('Simpan'), onPressed: () => Navigator.of(context).pop()), ], child: ShadInputFormField(id: 'release-title', label: const Text('Judul rilis'), initialValue: 'Senja di Kota'), ), ), ); }}Install
Section titled “Install”npx shadcn@latest add https://design.sosialoka.tech/r/react/dialog.jsonnpx shadcn-vue@latest add https://design.sosialoka.tech/r/vue/dialog.jsonThe button it installs is the Sosialoka button.
Accessibility
Section titled “Accessibility”- Renders
role="dialog"with the title as its name; focus moves into the dialog and returns to the trigger when it closes. - Escape closes it, and focus stays inside while it is open.
