Skip to main content

ButtonGroup

Lays out related buttons in a row with one shared gap and alignment.

import { ButtonGroup } from "@/fragments/ui";Source

Preview

<ButtonGroup>
  <Button variant="soft">Cancel</Button>
  <Button variant="solid">Save</Button>
</ButtonGroup>

Installation

npx @usefragments/cli add buttongroup

Writes src/fragments/ui/components/ButtonGroup plus what it imports, the globals stylesheet, and .fragments/registry-lock.json, then prints the packages to add. No account, no key.

Your own registry: publish from Fragments Cloud and add --registry org/name. Connect a workspace.

Examples

Spacing

Four gap steps, from touching to airy.

import { Stack } from '@/components/Stack';

<Stack direction="column" gap="md">
  <ButtonGroup gap="none">
    <Button variant="soft" size="sm">None</Button>
    <Button variant="soft" size="sm">Gap</Button>

Alignment

Pins the row to the left, centre, or right of its container.

import { Stack } from '@/components/Stack';

<Stack direction="column" gap="md">
  <ButtonGroup align="start">
    <Button variant="soft" size="sm">Start</Button>
    <Button variant="soft" size="sm">Aligned</Button>

Wrapping

Buttons drop to a second line instead of overflowing.

<ButtonGroup wrap>
  <Button variant="soft" size="sm">Approve</Button>
  <Button variant="soft" size="sm">Request changes</Button>
  <Button variant="soft" size="sm">Reassign reviewer</Button>
  <Button variant="soft" size="sm">Move to backlog</Button>
  <Button variant="soft" size="sm">Archive</Button>

Form Actions

Right-aligned pair, named for screen readers.

<ButtonGroup align="end" role="group" aria-label="Form actions">
  <Button variant="ghost">Cancel</Button>
  <Button variant="solid">Submit</Button>
</ButtonGroup>

API

Component props
Prop
Type
Default
Description
childrenRequirednodeNot setButton elements to group together
gapenumnonexssmmdsmSpacing between buttons
wrapbooleanfalseAllow buttons to wrap to next line
alignenumstartcenterendNot setAlignment of buttons

Accessibility

  • Each button stays individually focusable
  • Add role="group" plus aria-label when the set needs a name
  • Order buttons the way they read, not the way they look

Guidance

Use when

  • Confirm/cancel pairs at the end of a form
  • Toolbars and action bars
  • Pagination controls

Avoid when

  • Unrelated buttons — use Stack
  • Navigation links — use a nav element
  • A single button
  • ButtonchildButtonGroup contains Button components
  • StackalternativeUse Stack for more general layout needs

Next steps