RadioAPI
React Radio 组件的 API 参考文档。了解此导出模块的 props、CSS 和其他 API。
示例
导入
import Radio from '@mui/material/Radio';
// or
import { Radio } from '@mui/material';ButtonBase 组件的 Props 也可用。
| 名称 | 类型 | 默认 | 描述 |
|---|---|---|---|
| checked | bool | - | 如果为 |
| checkedIcon | node | <RadioButtonIcon checked /> | 组件被选中时显示的图标。 |
| classes | object | - | 覆盖或扩展应用于组件的样式。 有关更多详细信息,请参阅下面的CSS 类 API。 |
| color | 'default' | 'primary' | 'secondary' | 'error' | 'info' | 'success' | 'warning' | string | 'primary' | 组件的颜色。它支持默认主题颜色和自定义主题颜色,可以按照调色板自定义指南中所示的方式添加。 |
| disabled | bool | - | 如果为 |
| disableRipple | bool | false | 如果为 |
| icon | node | <RadioButtonIcon /> | 组件未选中时显示的图标。 |
| id | string | - |
|
| inputProps | object | - | 属性应用于 |
| inputRef | ref | - | 将 ref 传递给 |
| name | string | - |
|
| onChange | func | - | 状态更改时触发的回调。 签名: function(event: React.ChangeEvent
|
| required | bool | false | 如果为 |
| size | 'medium' | 'small' | string | 'medium' | 组件的大小。 |
| slotProps | { input?: func | object, root?: func | object } | {} | 用于每个内部插槽的 props。 |
| slots | { input?: elementType, root?: elementType } | {} | 用于每个内部插槽的组件。 |
| sx | Array<func | object | bool> | func | object | - | 允许定义系统覆盖以及其他 CSS 样式的系统 prop。 有关更多详细信息,请参阅 `sx` 页面。 |
| value | any | - | 组件的值。DOM API 将其强制转换为字符串。 |
ref 被转发到根元素。继承
虽然上面没有明确记录,但 Radio 中也提供了 ButtonBase 组件的 props。您可以利用它来定位嵌套组件。
主题默认 props
您可以使用 MuiRadio 通过主题更改此组件的默认 props。
| 插槽名称 | 类名 | 默认组件 | 描述 |
|---|---|---|---|
| root | .MuiRadio-root | SwitchBase | 渲染根插槽的组件。 |
| input | SwitchBase's input | 渲染 input 插槽的组件。 |
这些类名对于使用 CSS 进行样式设置很有用。当触发特定状态时,它们应用于组件的插槽。
| 类名 | 规则名称 | 描述 |
|---|---|---|
| .Mui-checked | 如果 checked={true},则应用于根元素的状态类。 | |
| .Mui-disabled | 如果 disabled={true},则应用于根元素的状态类。 | |
| .MuiRadio-colorPrimary | colorPrimary | 如果 color="primary",则应用于根元素的样式。 |
| .MuiRadio-colorSecondary | colorSecondary | 如果 color="secondary",则应用于根元素的样式。 |
| .MuiRadio-sizeSmall | sizeSmall | 如果 size="small",则应用于根元素的样式。 |
您可以使用以下自定义选项之一覆盖组件的样式
- 使用全局类名。
- 在自定义主题中,使用作为组件的
styleOverrides属性一部分的规则名称。
源代码
如果您在此页面中找不到信息,请考虑查看组件的实现以获取更多详细信息。