2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
|
|
|
|
category: Components
|
2016-07-21 10:10:04 +08:00
|
|
|
|
subtitle: 单选框
|
2022-11-09 12:28:04 +08:00
|
|
|
|
group: 数据录入
|
2016-07-21 10:10:04 +08:00
|
|
|
|
title: Radio
|
2022-11-30 20:14:41 +08:00
|
|
|
|
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*M-YKTJnWM2kAAAAAAAAAAAAADrJ8AQ/original
|
2023-02-09 22:17:31 +08:00
|
|
|
|
coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*a9roS6DHFIcAAAAAAAAAAAAADrJ8AQ/original
|
2022-11-09 12:28:04 +08:00
|
|
|
|
demo:
|
|
|
|
|
cols: 2
|
2016-03-31 14:17:09 +08:00
|
|
|
|
---
|
2015-07-16 18:23:25 +08:00
|
|
|
|
|
2015-07-28 20:22:37 +08:00
|
|
|
|
单选框。
|
|
|
|
|
|
2015-07-16 18:23:25 +08:00
|
|
|
|
## 何时使用
|
|
|
|
|
|
2015-07-16 22:40:49 +08:00
|
|
|
|
- 用于在多个备选项中选中单个状态。
|
|
|
|
|
- 和 Select 的区别是,Radio 所有选项默认可见,方便用户在比较中选择,因此选项不宜过多。
|
|
|
|
|
|
2022-11-09 12:28:04 +08:00
|
|
|
|
## 代码演示
|
|
|
|
|
|
2022-12-08 10:17:51 +08:00
|
|
|
|
<!-- prettier-ignore-start -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
<code src="./demo/basic.tsx">基本</code>
|
|
|
|
|
<code src="./demo/disabled.tsx">不可用</code>
|
|
|
|
|
<code src="./demo/radiogroup.tsx">单选组合</code>
|
|
|
|
|
<code src="./demo/radiogroup-more.tsx">Radio.Group 垂直</code>
|
|
|
|
|
<code src="./demo/radiogroup-options.tsx">Radio.Group 组合 - 配置方式</code>
|
|
|
|
|
<code src="./demo/radiobutton.tsx">按钮样式</code>
|
|
|
|
|
<code src="./demo/radiogroup-with-name.tsx">单选组合 - 配合 name 使用</code>
|
|
|
|
|
<code src="./demo/size.tsx">大小</code>
|
|
|
|
|
<code src="./demo/radiobutton-solid.tsx">填底的按钮样式</code>
|
2022-12-06 23:14:30 +08:00
|
|
|
|
<code src="./demo/badge.tsx" debug>测试 Badge 的样式</code>
|
|
|
|
|
<code src="./demo/wireframe.tsx" debug>线框风格</code>
|
2023-06-05 16:16:43 +08:00
|
|
|
|
<code src="./demo/component-token.tsx" debug>组件 Token</code>
|
2022-12-08 10:17:51 +08:00
|
|
|
|
<!-- prettier-ignore-end -->
|
2022-11-09 12:28:04 +08:00
|
|
|
|
|
2015-07-16 18:23:25 +08:00
|
|
|
|
## API
|
|
|
|
|
|
2020-02-26 16:09:22 +08:00
|
|
|
|
### Radio/Radio.Button
|
2015-07-17 16:06:46 +08:00
|
|
|
|
|
2022-12-08 10:17:51 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 |
|
|
|
|
|
| --- | --- | --- | --- |
|
|
|
|
|
| autoFocus | 自动获取焦点 | boolean | false |
|
|
|
|
|
| checked | 指定当前是否选中 | boolean | false |
|
|
|
|
|
| defaultChecked | 初始是否选中 | boolean | false |
|
|
|
|
|
| disabled | 禁用 Radio | boolean | false |
|
|
|
|
|
| value | 根据 value 进行比较,判断是否选中 | any | - |
|
2015-07-17 16:06:46 +08:00
|
|
|
|
|
2022-12-08 10:17:51 +08:00
|
|
|
|
### Radio.Group
|
2015-07-17 16:06:46 +08:00
|
|
|
|
|
2015-07-28 20:22:37 +08:00
|
|
|
|
单选框组合,用于包裹一组 `Radio`。
|
2015-07-20 22:36:49 +08:00
|
|
|
|
|
2022-12-08 10:17:51 +08:00
|
|
|
|
<!-- prettier-ignore -->
|
|
|
|
|
| 参数 | 说明 | 类型 | 默认值 | 版本 |
|
|
|
|
|
| --- | --- | --- | --- | --- |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| buttonStyle | RadioButton 的风格样式,目前有描边和填色两种风格 | `outline` \| `solid` | `outline` | | |
|
|
|
|
|
| defaultValue | 默认选中的值 | any | - | | |
|
2020-07-01 16:21:56 +08:00
|
|
|
|
| disabled | 禁选所有子单选器 | boolean | false | | |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| name | RadioGroup 下所有 `input[type="radio"]` 的 `name` 属性 | string | - | | |
|
2022-11-24 23:51:00 +08:00
|
|
|
|
| options | 以配置形式设置子元素 | string\[] \| number\[] \| Array<{ label: ReactNode; value: string; disabled?: boolean; }> | - | | |
|
2020-10-21 10:33:43 +08:00
|
|
|
|
| optionType | 用于设置 Radio `options` 类型 | `default` \| `button` | `default` | 4.4.0 | |
|
|
|
|
|
| size | 大小,只对按钮样式生效 | `large` \| `middle` \| `small` | - | | |
|
|
|
|
|
| value | 用于设置当前选中的值 | any | - | | |
|
|
|
|
|
| onChange | 选项变化时的回调函数 | function(e:Event) | - | | |
|
2017-12-01 19:28:41 +08:00
|
|
|
|
|
|
|
|
|
## 方法
|
|
|
|
|
|
|
|
|
|
### Radio
|
|
|
|
|
|
2022-01-12 22:57:43 +08:00
|
|
|
|
| 名称 | 描述 |
|
|
|
|
|
| ------- | -------- |
|
|
|
|
|
| blur() | 移除焦点 |
|
2019-11-22 14:37:39 +08:00
|
|
|
|
| focus() | 获取焦点 |
|
2023-04-11 10:25:24 +08:00
|
|
|
|
|
|
|
|
|
## Design Token
|
|
|
|
|
|
|
|
|
|
<ComponentTokenTable component="Radio"></ComponentTokenTable>
|