Files
2026-10-18 15:42:33 +08:00

58 lines
1.3 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Checkbox
允许用户在已选和未选之间切换的控件。
<WidgetExample name="checkbox-basic" />
## 适用场景
- **适用**:单条二元选择(同意条款、订阅开关)
- **适用**:表单中的勾选项
- **不适用**:互斥的多选一场景(用 `radio-group`)
## 用法
```tsx
import { Checkbox } from "@lcui/react"
```
```tsx
<Checkbox />
```
使用 `checked` 控制选中状态,状态变化时触发 `change` 事件。
## 示例
### 说明
配合 `FieldContent` 与 `FieldDescription` 为选项补充说明文字。
<WidgetExample name="checkbox-description" />
### 分组
用一组 `Field` 组合出复选框列表。
<WidgetExample name="checkbox-group" />
### 半选
`indeterminate` 用于表达“子项部分被选中”的视觉状态,此时显示减号图标。
<WidgetExample name="checkbox-indeterminate" />
### 禁用
<WidgetExample name="checkbox-disabled" />
## 注意事项
:::caution
**indeterminate 是状态,不是默认值**。半选态(`indeterminate="true"`)用于表达“子项部分被选中”的视觉状态(例如父级 checkbox 在部分子项被选时显示半选)。点击 indeterminate 状态的 checkbox 会转为 checked 状态。
:::
## API 参考
<FieldTable name="checkbox" />