Components
- 手风琴
- 提示
- 警告对话框
- 宽高比
- 头像
- 徽章
- 面包屑导航
- 按钮
- 按钮组
- 日历 Calendar
- 卡片
- Carousel
- 图表 Chart
- 复选框
- 折叠面板
- 组合框
- 命令
- 上下文菜单
- 数据表格 Data Table
- 日期选择器 Date Picker
- 对话框 Dialog
- 抽屉
- 下拉菜单
- Empty
- 字段
- 悬停卡片
- 输入
- 输入组
- 输入 OTP
- 项目
- Kbd
- 标签
- 菜单栏
- 原生选择框
- 导航菜单 Navigation Menu
- 分页
- 弹出框
- 进度 Progress
- 单选框组
- 可调整大小
- 滚动区域 Scroll Area
- 选择框
- 分隔符 Separator
- 侧边栏 Sheet
- 侧边栏 Sidebar
- 骨架屏
- 滑块
- Sonner
- 加载指示器 Spinner
- 开关
- 表格
- 标签页 Tabs
- 文本域
- 吐司
- 切换按钮 Toggle
- 切换组
- 提示 Tooltip
- 排版
By clicking this checkbox, you agree to the terms.
"use client"
import { Checkbox } from "@/components/ui/checkbox"安装
pnpm dlx shadcn@latest add checkbox
使用
import { Checkbox } from "@/components/ui/checkbox"<Checkbox />选中状态
使用 defaultChecked 处理非受控复选框,或者使用 checked 和
onCheckedChange 来控制状态。
import * as React from "react"
export function Example() {
const [checked, setChecked] = React.useState(false)
return <Checkbox checked={checked} onCheckedChange={setChecked} />
}无效状态
在复选框上设置 aria-invalid,并在字段包装组件上设置 data-invalid,
以显示无效的样式。
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
示例
基础
配合 Field 和 FieldLabel 使用复选框,以实现正确的布局和标签。
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
描述
使用 FieldContent 和 FieldDescription 来显示辅助文字。
By clicking this checkbox, you agree to the terms and conditions.
import { Checkbox } from "@/components/ui/checkbox"
import {
Field,禁用
使用 disabled 属性来禁止交互,并在 <Field> 组件添加 data-disabled 属性,以应用禁用样式。
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
组
使用多个字段来创建复选框列表。
import { Checkbox } from "@/components/ui/checkbox"
import {
Field,表格
| Name | Role | ||
|---|---|---|---|
| Sarah Chen | sarah.chen@example.com | Admin | |
| Marcus Rodriguez | marcus.rodriguez@example.com | User | |
| Priya Patel | priya.patel@example.com | User | |
| David Kim | david.kim@example.com | Editor |
"use client"
import * as React from "react"API 参考
更多信息请参考 Radix UI 文档。