跳转到内容

ButtonGroup API

想要学习更多组件属性和 CSS API,可以查阅 React ButtonGroup 组件的 API 文档。

演示项目

For examples and details on the usage of this React component, visit the component demo pages:

导入

import ButtonGroup from '@mui/material/ButtonGroup';
// 或
import { ButtonGroup } from '@mui/material';
你可以阅读这个关于最小化捆绑包的指南以了解以上二者的差异。

组件名称

在主题中,名称“MuiButtonGroup”可用于提供默认属性(props),或者样式覆盖

属性

原生(Native) 组件的属性也是可用的。

名称类型默认值描述
childrennode
The content of the component.
classesobject
Override or extend the styles applied to the component. See CSS API below for more details.
color'inherit'
| 'primary'
| 'secondary'
| 'error'
| 'info'
| 'success'
| 'warning'
| string
'primary'
The color of the component. It supports both default and custom theme colors, which can be added as shown in the palette customization guide.
componentelementType
The component used for the root node. Either a string to use a HTML element or a component.
disabledboolfalse
如果被设置为 true,那么该组件将会被禁用。
disableElevationboolfalse
If true, no elevation is used.
disableFocusRippleboolfalse
If true, the button keyboard focus ripple is disabled.
disableRippleboolfalse
If true, the button ripple effect is disabled.
fullWidthboolfalse
If true, the buttons will take up the full width of its container.
orientation'horizontal'
| 'vertical'
'horizontal'
The group orientation (layout flow direction).
size'small'
| 'medium'
| 'large'
| string
'medium'
The size of the button. small is equivalent to the dense button styling.
sxArray<func
| object
| bool>
| func
| object
The system prop that allows defining system overrides as well as additional CSS styles. See the `sx` page for more details.
variant'contained'
| 'outlined'
| 'text'
| string
'outlined'
The variant to use.

ref 则会被传递到根元素中。

CSS

规则名称全局类名描述
root.MuiButtonGroup-rootStyles applied to the root element.
contained.MuiButtonGroup-containedStyles applied to the root element if variant="contained".
outlined.MuiButtonGroup-outlinedStyles applied to the root element if variant="outlined".
text.MuiButtonGroup-textStyles applied to the root element if variant="text".
disableElevation.MuiButtonGroup-disableElevationStyles applied to the root element if disableElevation={true}.
disabled.Mui-disabledPseudo-class applied to the child elements if disabled={true}.
fullWidth.MuiButtonGroup-fullWidthStyles applied to the root element if fullWidth={true}.
vertical.MuiButtonGroup-verticalStyles applied to the root element if orientation="vertical".
grouped.MuiButtonGroup-groupedStyles applied to the children.
groupedHorizontal.MuiButtonGroup-groupedHorizontalStyles applied to the children if orientation="horizontal".
groupedVertical.MuiButtonGroup-groupedVerticalStyles applied to the children if orientation="vertical".
groupedText.MuiButtonGroup-groupedTextStyles applied to the children if variant="text".
groupedTextHorizontal.MuiButtonGroup-groupedTextHorizontalStyles applied to the children if variant="text" and orientation="horizontal".
groupedTextVertical.MuiButtonGroup-groupedTextVerticalStyles applied to the children if variant="text" and orientation="vertical".
groupedTextPrimary.MuiButtonGroup-groupedTextPrimaryStyles applied to the children if variant="text" and color="primary".
groupedTextSecondary.MuiButtonGroup-groupedTextSecondaryStyles applied to the children if variant="text" and color="secondary".
groupedOutlined.MuiButtonGroup-groupedOutlinedStyles applied to the children if variant="outlined".
groupedOutlinedHorizontal.MuiButtonGroup-groupedOutlinedHorizontalStyles applied to the children if variant="outlined" and orientation="horizontal".
groupedOutlinedVertical.MuiButtonGroup-groupedOutlinedVerticalStyles applied to the children if variant="outlined" and orientation="vertical".
groupedOutlinedPrimary.MuiButtonGroup-groupedOutlinedPrimaryStyles applied to the children if variant="outlined" and color="primary".
groupedOutlinedSecondary.MuiButtonGroup-groupedOutlinedSecondaryStyles applied to the children if variant="outlined" and color="secondary".
groupedContained.MuiButtonGroup-groupedContainedStyles applied to the children if variant="contained".
groupedContainedHorizontal.MuiButtonGroup-groupedContainedHorizontalStyles applied to the children if variant="contained" and orientation="horizontal".
groupedContainedVertical.MuiButtonGroup-groupedContainedVerticalStyles applied to the children if variant="contained" and orientation="vertical".
groupedContainedPrimary.MuiButtonGroup-groupedContainedPrimaryStyles applied to the children if variant="contained" and color="primary".
groupedContainedSecondary.MuiButtonGroup-groupedContainedSecondaryStyles applied to the children if variant="contained" and color="secondary".

您可以使用组件自定义选项对组件进行个性化: