Skip to content

Button Group

Join related buttons, inputs and menus into one strip.

import { ButtonGroup, ButtonGroupSeparator, ButtonGroupText } from '@youj/react'

Installation & usage

npm i @youj/react

For 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.

Reference

Propsorientation (1)

Props

ButtonGroup

ButtonGroup props
PropType
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 an aria-label when 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 separator with aria-orientation. Name icon-only buttons with aria-label.