By clicking this checkbox, you agree to the terms.
"use client"
import { Checkbox } from "@/components/ui/checkbox"安装
🌐 Installation
pnpm dlx shadcn@latest add checkbox
用法
🌐 Usage
import { Checkbox } from "@/components/ui/checkbox"<Checkbox />已选状态
🌐 Checked State
对于不受控的复选框使用 defaultChecked,或者使用 checked 和 onCheckedChange 来控制状态。
🌐 Use defaultChecked for uncontrolled checkboxes, or checked and
onCheckedChange to control the state.
import * as React from "react"
export function Example() {
const [checked, setChecked] = React.useState(false)
return <Checkbox checked={checked} onCheckedChange={setChecked} />
}无效状态
🌐 Invalid State
在复选框上设置 aria-invalid,在字段封装器上设置 data-invalid 以显示无效样式。
🌐 Set aria-invalid on the checkbox and data-invalid on the field wrapper to
show the invalid styles.
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
示例
🌐 Examples
基础
🌐 Basic
将复选框与 Field 和 FieldLabel 配对,以实现正确的布局和标注。
🌐 Pair the checkbox with Field and FieldLabel for proper layout and labeling.
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
描述
🌐 Description
使用 FieldContent 和 FieldDescription 作为辅助文本。
🌐 Use FieldContent and FieldDescription for helper text.
By clicking this checkbox, you agree to the terms and conditions.
import { Checkbox } from "@/components/ui/checkbox"
import {
Field,已禁用
🌐 Disabled
使用 disabled 属性来防止交互,并在 <Field> 组件上添加 data-disabled 属性以应用禁用样式。
🌐 Use the disabled prop to prevent interaction and add the data-disabled attribute to the <Field> component for disabled styles.
import { Checkbox } from "@/components/ui/checkbox"
import { Field, FieldGroup, FieldLabel } from "@/components/ui/field"
群组
🌐 Group
使用多个字段来创建复选框列表。
🌐 Use multiple fields to create a checkbox list.
import { Checkbox } from "@/components/ui/checkbox"
import {
Field,表格
🌐 Table
| 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 配置指南。
🌐 To enable RTL support in shadcn/ui, see the RTL configuration guide.
بالنقر على هذا المربع، فإنك توافق على الشروط.
"use client"
import * as React from "react"API参考
🌐 API Reference
有关更多信息,请参阅 Radix UI 文档。
🌐 See the Radix UI documentation for more information.