109k

对话框 (Dialog)

覆盖在主窗口或其他对话框窗口之上的窗口,使底层内容处于停用状态。

Radix UIBase UI
Radix UI - shadcn/ui 组件库
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 文档以获取更多信息。