Button Group
Join related buttons, inputs and menus into one strip.
import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText } from '@youj/react'
Installation & usage
npm i @youj/reactFor an app already set up with npx @youj/cli init, which installs the peers (@youj/core, @youj/motion, motion and Base UI) and wires the provider. New app? Start at Installation.
Use a button group when a few actions belong together and should read as one control: previous and next, a split button with its options, a search field with its button. For a set of options where one is chosen, use a Toggle Group. For a long, dense row of controls that should be one tab stop, use a Toolbar.
import { Button, ButtonGroup } from '@youj/react'
export function Pager() {
return (
<ButtonGroup aria-label="Pages">
<Button variant="outline">Previous</Button>
<Button variant="outline">Next</Button>
</ButtonGroup>
)
}The group takes away the inner corners and the doubled border where members meet, and a focused member rises above its neighbors so its ring isn't clipped. Corners are start and end, not left and right, so a group mirrors in right-to-left layouts. Nest groups to make clusters with a gap between them. The API matches shadcn/ui's Button Group.
Description
Nested groups of icon and text buttons, and a split Merge button with a menu half.
Filled buttons have no border, so put a ButtonGroupSeparator between them to draw the seam. The menu half is a Dropdown Menu whose trigger renders as a Button.
A search input with its button, a URL input with a text prefix, and a vertical zoom pair.
Inputs, selects and a ButtonGroupText join the same strip. ButtonGroupText renders any element through render, so a prefix can be the input's label. Set orientation="vertical" to stack the members.
Code
button-group-demo.tsx, the Demo story. The component itself comes from the package.
Reference
Propsorientation (1)
Props
ButtonGroup
| Prop | Type | |
|---|---|---|
orientation | 'horizontal' | 'vertical'default 'horizontal' | 'horizontal' |
ButtonGroupSeparator
ButtonGroupSeparator adds no props of its own. They pass through to ComponentProps<typeof Separator>.
ButtonGroupText takes render and any div props.
Reduced motionThe group itself doesn't move
Reduced motion
The group itself doesn't move. Its buttons keep their own behavior: under reduced motion they don't scale when pressed.
AccessibilityKeyboard, ARIA
Accessibility
- The group is a
group; give it anaria-labelwhen its purpose isn't obvious from its buttons. - Every member keeps its own role, name and tab stop. If the group is long and dense enough that tabbing through it is a chore, use a Toolbar instead, which is one tab stop.
- The separator is a
separatorwitharia-orientation. Name icon-only buttons witharia-label.