111k

Dialog

覆盖在主窗口或另一个对话框之上的窗口,会让下方内容失效。

import { Button } from "@/components/ui/button"
import {
  Dialog,

安装

pnpm dlx shadcn@latest add dialog

用法

import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogHeader,
  DialogTitle,
  DialogTrigger,
} from "@/components/ui/dialog"
<Dialog>
  <DialogTrigger>Open</DialogTrigger>
  <DialogContent>
    <DialogHeader>
      <DialogTitle>Are you absolutely sure?</DialogTitle>
      <DialogDescription>
        This action cannot be undone. This will permanently delete your account
        and remove your data from our servers.
      </DialogDescription>
    </DialogHeader>
  </DialogContent>
</Dialog>

示例

自定义关闭按钮

用你自己的按钮替换默认关闭控件。

import { Button } from "@/components/ui/button"
import {
  Dialog,

无关闭按钮

使用 showCloseButton={false} 隐藏关闭按钮。

import { Button } from "@/components/ui/button"
import {
  Dialog,

固定页脚

在内容滚动时保持操作按钮可见。

import { Button } from "@/components/ui/button"
import {
  Dialog,

可滚动内容

长内容可以滚动,而头部保持可见。

import { Button } from "@/components/ui/button"
import {
  Dialog,

RTL

要在 shadcn/ui 中启用 RTL 支持,请参见 RTL 配置指南

"use client"

import { Button } from "@/examples/radix/ui-rtl/button"

API 参考

更多信息请参见 Radix UI 文档。