mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-04 00:49:39 +08:00
7fd093bd0a
* docs: add general components TS demo * docs: add layout components TS demo * docs: add navigation components TS demo * docs: add data entry components TS demo * chore(deps): add types for qs * docs: add data display TS demo * docs: add feedback components TS demo * docs: add other components TS demo * chore(deps): add types * docs: unified demo code style * docs: fix lint error * docs: add demo TS type * docs: fix demo TS type * test: update snapshot * docs: fix TS demo * feat: update Rate character type * docs: fix lint error * feat: update Rate character type * feat: update Rate character type
2.1 KiB
2.1 KiB
order | title | ||||
---|---|---|---|---|---|
2 |
|
zh-CN
通过配置 options
参数来渲染单选框。也可通过 optionType
参数来设置 Radio 类型。
en-US
Render radios by configuring options
. Radio type can also be set through the optionType
parameter.
import React, { useState } from 'react';
import { Radio } from 'antd';
import type { RadioChangeEvent } from 'antd';
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' },
{ label: 'Orange', value: 'Orange', disabled: true },
];
const App: React.FC = () => {
const [value1, setValue1] = useState('Apple');
const [value2, setValue2] = useState('Apple');
const [value3, setValue3] = useState('Apple');
const [value4, setValue4] = useState('Apple');
const onChange1 = ({ target: { value } }: RadioChangeEvent) => {
console.log('radio1 checked', value);
setValue1(value);
};
const onChange2 = ({ target: { value } }: RadioChangeEvent) => {
console.log('radio2 checked', value);
setValue2(value);
};
const onChange3 = ({ target: { value } }: RadioChangeEvent) => {
console.log('radio3 checked', value);
setValue3(value);
};
const onChange4 = ({ target: { value } }: RadioChangeEvent) => {
console.log('radio4 checked', value);
setValue4(value);
};
return (
<>
<Radio.Group options={plainOptions} onChange={onChange1} value={value1} />
<br />
<Radio.Group options={optionsWithDisabled} onChange={onChange2} value={value2} />
<br />
<br />
<Radio.Group options={options} onChange={onChange3} value={value3} optionType="button" />
<br />
<br />
<Radio.Group
options={optionsWithDisabled}
onChange={onChange4}
value={value4}
optionType="button"
buttonStyle="solid"
/>
</>
);
};
export default App;