Button Group
A container that groups related buttons with shared borders and outer corners only.
Installation
Needs the arene setup first. Also adds Button.
Install the packages it imports:
Set up the token layer and the StyleX compiler, if you have not already. See
Installation. ButtonGroup also needs the
Button, which it imports ButtonGroupContext and
buttonStyles from.
Paste this source into the file named in its title.
Change the @/ imports if your project uses different aliases.
Usage
Give every group an aria-label or aria-labelledby. Without one, a screen
reader announces the group with no name.
Use ButtonGroup for buttons that each perform an action. Buttons that toggle a
shared state are a toggle group, which arene does not ship yet.
Orientation
Set orientation="vertical" to stack the members.
Size
The group takes no size. Set it on each button, and give every member the
same one.
Side by side
Nesting a group inside another group does nothing. To place groups side by
side, put them in an HStack and set the space between them with its gap.
Separator
Use ButtonGroupSeparator between solid variants, which have no visible
border of their own. It runs across the group's axis.
Split button
Pair an action with a menu that offers the alternatives. The menu trigger
renders a Button, so it joins the group like any other member.
With text
Use ButtonGroupText for an inert member, such as a label or a unit. Pass
render to change the element.
npm install @base-ui/reactAPI reference
Pass render to replace a part's element or compose it with another component.
ButtonGroup
Renders a div with role="group". A member is any child carrying a
data-slot.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | "horizontal" |
xstyle | StyleXStyles | — |
className | string | — |
ButtonGroupSeparator
Wraps Base UI's Separator.
| Prop | Type | Default |
|---|---|---|
orientation | "horizontal" | "vertical" | across the group's axis |
xstyle | StyleXStyles | — |
className | string | — |
ButtonGroupText
Renders a div through Base UI's useRender, so render swaps the element.
| Prop | Type | Default |
|---|---|---|
render | ReactElement | — |
xstyle | StyleXStyles | — |
className | string | — |
Data attributes
| Attribute | On | Effect |
|---|---|---|
data-slot="button-group" | the group | Targets the group from a parent |
data-orientation | the group | Reflects the orientation prop |
data-slot="button-group-separator" | the separator | Targets the separator |
data-slot="button-group-text" | the text | Targets the text member |