# 复选框 · JGuang UI

> 从多个独立选项中选择零项或多项。

- 页面: https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox
- 改编自: shadcn/ui 文档 (MIT) @ bc0705384b51252af26dcc65425b216bf5eb063c
- 说明：正文保留英文原文。

> 示例 `checkbox-demo`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Installation


  

**Command**


  

**Manual**


```text
Use the JGuang UI Registry URL provided on /systems/jguang-ui#install.
```


### Install the following dependencies:


```bash
npm install @base-ui/react
```


### Copy and paste the following code into your project.


[View complete source: components/ui/checkbox.tsx](/r/jguang-ui/base/checkbox.json)


### Update the import paths to match your project setup.


## Usage

```tsx
import { Checkbox } from "@/components/ui/checkbox"
```

```tsx
<Checkbox />
```

## Checked State

Use `defaultChecked` for uncontrolled checkboxes, or `checked` and
`onCheckedChange` to control the state.

```tsx showLineNumbers
import * as React from "react"

export function Example() {
  const [checked, setChecked] = React.useState(false)

  return <Checkbox checked={checked} onCheckedChange={setChecked} />
}
```

## Invalid State

Set `aria-invalid` on the checkbox and `data-invalid` on the field wrapper to
show the invalid styles.


> 示例 `checkbox-invalid`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Basic

Pair the checkbox with `Field` and `FieldLabel` for proper layout and labeling.


> 示例 `checkbox-basic`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Description

Use `FieldContent` and `FieldDescription` for helper text.


> 示例 `checkbox-description`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Disabled

Use the `disabled` prop to prevent interaction and add the `data-disabled` attribute to the `<Field>` component for disabled styles.


> 示例 `checkbox-disabled`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Group

Use multiple fields to create a checkbox list.


> 示例 `checkbox-group`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## Table


> 示例 `checkbox-table`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## RTL

To enable RTL support in JGuang UI, see the [RTL configuration guide](/systems/jguang-ui/docs/rtl).


> 示例 `checkbox-rtl`: 交互预览见 https://jiguang132.com/zh/systems/jguang-ui/docs/components/base/checkbox


## API Reference

See the [Base UI](https://base-ui.com/react/components/checkbox#api-reference) documentation for more information.

---

JGuang 全部资源索引: https://jiguang132.com/llms.txt
