apps/docs/content/docs/react/components/(buttons)/button-group.mdx
import { ButtonGroup, Button } from '@heroui/react';
<ComponentPreview name="button-group-basic" />
Import the ButtonGroup component and access all parts using dot notation.
import { ButtonGroup, Button } from '@heroui/react';
export default () => (
<ButtonGroup>
<Button>First</Button>
<Button>
<ButtonGroup.Separator />
Second
</Button>
<Button>
<ButtonGroup.Separator />
Third
</Button>
</ButtonGroup>
);
ButtonGroup wraps multiple Button components together, applying consistent styling, spacing, and automatic border radius handling. It uses React Context to pass
size,variant, andisDisabledprops to all child buttons.
<ComponentPreview name="button-group-variants" />
<ComponentPreview name="button-group-sizes" />
Use the orientation prop to arrange buttons horizontally or vertically.
<ComponentPreview name="button-group-orientation" />
<ComponentPreview name="button-group-with-icons" />
<ComponentPreview name="button-group-full-width" />
<ComponentPreview name="button-group-disabled" />
Simply omit the <ButtonGroup.Separator /> component from your buttons.
<ComponentPreview name="button-group-without-separator" />
<RelatedComponents component="button-group" />import { ButtonGroup, Button } from '@heroui/react';
function CustomButtonGroup() {
return (
<ButtonGroup className="gap-2">
<Button>First</Button>
<Button>
<ButtonGroup.Separator />
Second
</Button>
<Button>
<ButtonGroup.Separator />
Third
</Button>
</ButtonGroup>
);
}
To customize the ButtonGroup component classes, you can use the @layer components directive.
@layer components {
.button-group {
@apply gap-2 rounded-lg;
}
.button-group__separator {
@apply opacity-25;
}
}
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The ButtonGroup component uses these CSS classes (View source styles):
.button-group - Base button group container.button-group--full-width - Full width modifier.button-group__separator - Separator element between buttonsThe ButtonGroup component automatically applies border radius to buttons:
Add <ButtonGroup.Separator /> inside each Button (except the first) to show dividers between buttons.
| Prop | Type | Default | Description |
|---|---|---|---|
variant | 'primary' | 'secondary' | 'tertiary' | 'ghost' | 'danger' | - | Visual style variant applied to all buttons in the group |
size | 'sm' | 'md' | 'lg' | - | Size applied to all buttons in the group |
orientation | 'horizontal' | 'vertical' | 'horizontal' | The orientation of the button group |
fullWidth | boolean | false | Whether the button group should take full width of its container |
isDisabled | boolean | false | Whether all buttons in the group are disabled (can be overridden on individual buttons) |
className | string | - | Additional CSS classes |
children | React.ReactNode | - | Button components to group together |
| Prop | Type | Default | Description |
|---|---|---|---|
className | string | - | Additional CSS classes |
size, variant, and isDisabled props to all child Button componentsisDisabled prop by setting isDisabled={false}<ButtonGroup.Separator /> inside each Button (except the first) to show dividers between buttons