2017-07-31 11:33:47 +08:00
---
order: 4
title:
zh-CN: 单选组合 - 配合 name 使用
2019-05-27 21:32:45 +08:00
en-US: Radio.Group with name
2017-07-31 11:33:47 +08:00
---
## zh-CN
2019-05-27 21:32:45 +08:00
可以为 Radio.Group 配置 `name` 参数,为组合内的 input 元素赋予相同的 `name` 属性,使浏览器把 Radio.Group 下的 Radio 真正看作是一组(例如可以通过方向键始终**在同一组内**更改选项)。
2017-07-31 11:33:47 +08:00
## en-US
2019-05-27 21:32:45 +08:00
Passing the `name` property to all `input[type="radio"]` that are in the same Radio.Group. It is usually used to let the browser see your Radio.Group as a real "group" and keep the default behavior. For example, using left/right keyboard arrow to change your selection that in the same Radio.Group.
2017-07-31 11:33:47 +08:00
2022-05-19 09:46:26 +08:00
```tsx
2017-07-31 11:33:47 +08:00
import { Radio } from 'antd';
2022-05-23 14:37:16 +08:00
import React from 'react';
2018-06-27 15:55:04 +08:00
2022-05-19 09:46:26 +08:00
const App: React.FC = () => (
2020-03-30 22:14:13 +08:00
< Radio.Group name = "radiogroup" defaultValue = {1} >
< Radio value = {1} > A< / Radio >
< Radio value = {2} > B< / Radio >
< Radio value = {3} > C< / Radio >
< Radio value = {4} > D< / Radio >
< / Radio.Group >
);
2017-07-31 11:33:47 +08:00
2022-04-15 16:20:56 +08:00
export default App;
2017-07-31 11:33:47 +08:00
```