Components
- Accordion
- Alert
- Alert Dialog
- Aspect Ratio
- Avatar
- Badge
- Breadcrumb
- Button
- Button Group
- Calendar
- Card
- Carousel
- Chart
- Checkbox
- Collapsible
- Combobox
- Command
- Context Menu
- Data Table
- Date Picker
- Dialog
- Direction
- Drawer
- Dropdown Menu
- Empty
- Field
- Hover Card
- Input
- Input Group
- Input OTP
- Item
- Kbd
- Label
- Menubar
- Native Select
- Navigation Menu
- Pagination
- Popover
- Progress
- Radio Group
- Resizable
- Scroll Area
- Select
- Separator
- Sheet
- Sidebar
- Skeleton
- Slider
- Sonner
- Spinner
- Switch
- Table
- Tabs
- Textarea
- Toast
- Toggle
- Toggle Group
- Tooltip
- Typography
Get Started
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"RTL
要在 shadcn/ui 中启用 RTL 支持,请参见 RTL 配置指南。
بالنقر على هذا المربع، فإنك توافق على الشروط.
"use client"
import * as React from "react"API 参考
更多信息请参见 Base UI 文档。