2016-03-31 14:17:09 +08:00
|
|
|
---
|
|
|
|
category: Components
|
2016-09-21 11:28:38 +08:00
|
|
|
subtitle: 多选框
|
2022-11-09 12:28:04 +08:00
|
|
|
group: 数据录入
|
2016-09-21 11:28:38 +08:00
|
|
|
title: Checkbox
|
2022-11-30 20:14:41 +08:00
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*DzgiRbW3khIAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*G3MjTYXL6AIAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
demo:
|
|
|
|
cols: 2
|
2016-03-31 14:17:09 +08:00
|
|
|
---
|
2015-07-15 15:19:24 +08:00
|
|
|
|
|
|
|
多选框。
|
|
|
|
|
|
|
|
## 何时使用
|
|
|
|
|
2016-01-13 21:56:51 +08:00
|
|
|
- 在一组可选项中进行多项选择时;
|
|
|
|
- 单独使用可以表示两种状态之间的切换,和 `switch` 类似。区别在于切换 `switch` 会直接触发状态改变,而 `checkbox` 一般用于状态标记,需要和提交操作配合。
|
2015-07-15 15:19:24 +08:00
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
## 代码演示
|
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
<!-- prettier-ignore -->
|
2022-11-09 12:28:04 +08:00
|
|
|
<code src="./demo/basic.tsx">基本用法</code>
|
|
|
|
<code src="./demo/disabled.tsx">不可用</code>
|
|
|
|
<code src="./demo/controller.tsx">受控的 Checkbox</code>
|
|
|
|
<code src="./demo/group.tsx">Checkbox 组</code>
|
|
|
|
<code src="./demo/check-all.tsx">全选</code>
|
|
|
|
<code src="./demo/layout.tsx">布局</code>
|
|
|
|
<code src="./demo/debug-line.tsx" debug>同行布局</code>
|
2022-12-26 23:35:18 +08:00
|
|
|
<code src="./demo/debug-disable-popover.tsx" debug>禁用下的 Tooltip</code>
|
2022-11-09 12:28:04 +08:00
|
|
|
|
2015-07-15 15:19:24 +08:00
|
|
|
## API
|
|
|
|
|
2018-06-03 16:28:10 +08:00
|
|
|
#### Checkbox
|
2015-07-15 15:19:24 +08:00
|
|
|
|
2022-12-06 21:09:59 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
|
|
|
| autoFocus | 自动获取焦点 | boolean | false | |
|
|
|
|
| checked | 指定当前是否选中 | boolean | false | |
|
|
|
|
| defaultChecked | 初始是否选中 | boolean | false | |
|
|
|
|
| disabled | 失效状态 | boolean | false | |
|
|
|
|
| indeterminate | 设置 indeterminate 状态,只负责样式控制 | boolean | false | |
|
2023-02-05 11:13:38 +08:00
|
|
|
| onChange | 变化时的回调函数 | (e: CheckboxChangeEvent) => void | - | |
|
2015-12-24 15:03:06 +08:00
|
|
|
|
2018-06-03 16:28:10 +08:00
|
|
|
#### Checkbox Group
|
2015-12-24 15:03:06 +08:00
|
|
|
|
2022-11-17 17:31:26 +08:00
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
| --- | --- | --- | --- | --- |
|
2022-12-06 21:09:59 +08:00
|
|
|
| defaultValue | 默认选中的选项 | (string \| number)\[] | \[] | |
|
2022-11-17 17:31:26 +08:00
|
|
|
| disabled | 整组失效 | boolean | false | |
|
|
|
|
| name | CheckboxGroup 下所有 `input[type="checkbox"]` 的 `name` 属性 | string | - | |
|
|
|
|
| options | 指定可选项 | string\[] \| number\[] \| Option\[] | \[] | |
|
2023-03-12 17:37:32 +08:00
|
|
|
| value | 指定选中的选项 | (string \| number \| boolean)\[] | \[] | |
|
2023-02-05 11:13:38 +08:00
|
|
|
| onChange | 变化时的回调函数 | (checkedValue: CheckboxValueType[]) => void | - | |
|
2017-12-01 19:28:41 +08:00
|
|
|
|
2019-12-01 15:46:17 +08:00
|
|
|
##### Option
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
interface Option {
|
|
|
|
label: string;
|
|
|
|
value: string;
|
|
|
|
disabled?: boolean;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-06-03 16:28:10 +08:00
|
|
|
### 方法
|
2017-12-01 19:28:41 +08:00
|
|
|
|
2018-06-03 16:28:10 +08:00
|
|
|
#### Checkbox
|
2017-12-01 19:28:41 +08:00
|
|
|
|
2022-01-12 22:57:43 +08:00
|
|
|
| 名称 | 描述 | 版本 |
|
|
|
|
| ------- | -------- | ---- |
|
|
|
|
| blur() | 移除焦点 | |
|
|
|
|
| focus() | 获取焦点 | |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Checkbox"></ComponentTokenTable>
|