Button Group
A container that groups related buttons together with consistent styling.
Usage
import { ButtonGroup } from "@smartacteam/ambient-web/button-group";<ButtonGroup.Root>
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup.Root>Accessibility
- The
ButtonGroupcomponent has theroleattribute set togroup. - Use
tabto navigate between the buttons in the group. - Use
aria-labeloraria-labelledbyto label the button group.
<ButtonGroup.Root aria-label="Button group">
<Button>Button 1</Button>
<Button>Button 2</Button>
</ButtonGroup.Root>ButtonGroup vs ToggleGroup
- Use the
ButtonGroupcomponent when you want to group buttons that perform an action. - Use the
ToggleGroupcomponent when you want to group buttons that toggle a state.
Examples
Orientation
Set the orientation prop to change the button group layout.
Size
Control the size of buttons using the size prop on individual buttons.
Nested
Nest <ButtonGroup> components to create button groups with spacing.
Separator
The ButtonGroupSeparator component visually divides buttons within a group.
Buttons with variant default do not need a separator since they have a border. For variant primary, a separator is recommended to improve the visual hierarchy. Other button variants are not recommended for button groups.
Split
Create a split button group by adding two buttons separated by a ButtonGroupSeparator.
Input
Wrap an Input component with buttons.
Menu
Create a split button group with a Menu component.
Select
Pair with a Select component.
Popover
Use with a Popover component.