2017-03-28 11:56:38 +08:00
|
|
|
---
|
|
|
|
order: 2
|
|
|
|
title:
|
2019-05-27 21:32:45 +08:00
|
|
|
zh-CN: Radio.Group 组合 - 配置方式
|
|
|
|
en-US: Radio.Group group - optional
|
2017-03-28 11:56:38 +08:00
|
|
|
---
|
|
|
|
|
|
|
|
## zh-CN
|
|
|
|
|
2020-06-11 13:21:54 +08:00
|
|
|
通过配置 `options` 参数来渲染单选框。也可通过 `optionType` 参数来设置 Radio 类型。
|
2017-04-05 11:20:37 +08:00
|
|
|
|
2017-03-28 11:56:38 +08:00
|
|
|
## en-US
|
|
|
|
|
2020-06-11 13:21:54 +08:00
|
|
|
Render radios by configuring `options`. Radio type can also be set through the `optionType` parameter.
|
2017-04-05 11:20:37 +08:00
|
|
|
|
2017-03-28 11:56:38 +08:00
|
|
|
```jsx
|
|
|
|
import { Radio } from 'antd';
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2017-03-28 11:56:38 +08:00
|
|
|
const plainOptions = ['Apple', 'Pear', 'Orange'];
|
|
|
|
const options = [
|
|
|
|
{ label: 'Apple', value: 'Apple' },
|
|
|
|
{ label: 'Pear', value: 'Pear' },
|
|
|
|
{ label: 'Orange', value: 'Orange' },
|
|
|
|
];
|
|
|
|
const optionsWithDisabled = [
|
|
|
|
{ label: 'Apple', value: 'Apple' },
|
|
|
|
{ label: 'Pear', value: 'Pear' },
|
2020-06-11 13:21:54 +08:00
|
|
|
{ label: 'Orange', value: 'Orange', disabled: true },
|
2017-03-28 11:56:38 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
class App extends React.Component {
|
|
|
|
state = {
|
|
|
|
value1: 'Apple',
|
|
|
|
value2: 'Apple',
|
|
|
|
value3: 'Apple',
|
2020-06-11 13:21:54 +08:00
|
|
|
value4: 'Apple',
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
onChange1 = e => {
|
2017-03-28 11:56:38 +08:00
|
|
|
console.log('radio1 checked', e.target.value);
|
|
|
|
this.setState({
|
|
|
|
value1: e.target.value,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
onChange2 = e => {
|
2017-03-28 11:56:38 +08:00
|
|
|
console.log('radio2 checked', e.target.value);
|
|
|
|
this.setState({
|
|
|
|
value2: e.target.value,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2019-05-07 14:57:32 +08:00
|
|
|
onChange3 = e => {
|
2017-03-28 11:56:38 +08:00
|
|
|
console.log('radio3 checked', e.target.value);
|
|
|
|
this.setState({
|
|
|
|
value3: e.target.value,
|
|
|
|
});
|
2019-05-07 14:57:32 +08:00
|
|
|
};
|
2018-06-27 15:55:04 +08:00
|
|
|
|
2020-06-11 13:21:54 +08:00
|
|
|
onChange4 = e => {
|
|
|
|
console.log('radio4 checked', e.target.value);
|
|
|
|
this.setState({
|
|
|
|
value4: e.target.value,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-03-28 11:56:38 +08:00
|
|
|
render() {
|
2020-06-11 13:21:54 +08:00
|
|
|
const { value1, value2, value3, value4 } = this.state;
|
2017-03-28 11:56:38 +08:00
|
|
|
return (
|
2020-03-30 22:14:13 +08:00
|
|
|
<>
|
|
|
|
<Radio.Group options={plainOptions} onChange={this.onChange1} value={value1} />
|
2020-06-11 13:21:54 +08:00
|
|
|
<br />
|
|
|
|
<Radio.Group options={optionsWithDisabled} onChange={this.onChange2} value={value2} />
|
|
|
|
<br />
|
|
|
|
<br />
|
2019-05-27 21:32:45 +08:00
|
|
|
<Radio.Group
|
2020-06-11 13:21:54 +08:00
|
|
|
options={options}
|
2019-05-07 14:57:32 +08:00
|
|
|
onChange={this.onChange3}
|
2020-03-30 22:14:13 +08:00
|
|
|
value={value3}
|
2020-06-11 13:21:54 +08:00
|
|
|
optionType="button"
|
|
|
|
/>
|
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<Radio.Group
|
|
|
|
options={optionsWithDisabled}
|
|
|
|
onChange={this.onChange4}
|
|
|
|
value={value4}
|
|
|
|
optionType="button"
|
|
|
|
buttonStyle="solid"
|
2019-05-07 14:57:32 +08:00
|
|
|
/>
|
2020-03-30 22:14:13 +08:00
|
|
|
</>
|
2017-03-28 11:56:38 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ReactDOM.render(<App />, mountNode);
|
2017-04-05 11:20:37 +08:00
|
|
|
```
|