Skip to content
All components
Primitives

Button group

Join closely related buttons into one visual unit with shared borders, while each button keeps its own semantics and behavior.

Joins adjacent buttons into one control.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add button-group

Then import it from @/components/ui/button-group. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

Horizontal

Group related actions side by side. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { AlignCenterIcon, AlignLeftIcon, AlignRightIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group"

export function ButtonGroupHorizontal() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Text alignment">
        <Button emphasis="stroke" intent="neutral" aria-label="Align left">
          <AlignLeftIcon />
        </Button>
        <ButtonGroupSeparator />
        <Button emphasis="stroke" intent="neutral" aria-label="Align center">
          <AlignCenterIcon />
        </Button>
        <ButtonGroupSeparator />
        <Button emphasis="stroke" intent="neutral" aria-label="Align right">
          <AlignRightIcon />
        </Button>
      </ButtonGroup>
    </div>
  )
}

Vertical

Stack related actions vertically without changing their individual semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Button } from "@/components/ui/button"
import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group"

export function ButtonGroupVertical() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup orientation="vertical" aria-label="Calendar range">
        <Button emphasis="stroke" intent="neutral">
          Day
        </Button>
        <ButtonGroupSeparator />
        <Button emphasis="stroke" intent="neutral">
          Week
        </Button>
        <ButtonGroupSeparator />
        <Button emphasis="stroke" intent="neutral">
          Month
        </Button>
      </ButtonGroup>
    </div>
  )
}

Text actions

Join two text actions with leading and trailing icons. Each button keeps its own name and native activation; the group is named for context.

"use client"

import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupTextActions() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Results pages">
        <Button emphasis="stroke" intent="neutral">
          <ChevronLeftIcon />
          Previous
        </Button>
        <Button emphasis="stroke" intent="neutral">
          Next
          <ChevronRightIcon />
        </Button>
      </ButtonGroup>
    </div>
  )
}

Small

Group small buttons for a compact control row. Button size is set on each child; ButtonGroup only manages corners and shared borders.

"use client"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupSmall() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Zoom">
        <Button size="sm" emphasis="stroke" intent="neutral">
          Zoom out
        </Button>
        <Button size="sm" emphasis="stroke" intent="neutral">
          100%
        </Button>
        <Button size="sm" emphasis="stroke" intent="neutral">
          Zoom in
        </Button>
      </ButtonGroup>
    </div>
  )
}

Split button

Pair a primary action with a menu of related options. The icon-only trigger has its own accessible name and opens a real dropdown menu.

"use client"

import { ChevronDownIcon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { ButtonGroup, ButtonGroupSeparator } from "@/components/ui/button-group"
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu"

export function ButtonGroupSplitButton() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Save">
        <Button>Save draft</Button>
        <ButtonGroupSeparator />
        <DropdownMenu>
          <DropdownMenuTrigger asChild>
            <Button iconOnly aria-label="More save options">
              <ChevronDownIcon />
            </Button>
          </DropdownMenuTrigger>
          <DropdownMenuContent align="end">
            <DropdownMenuItem>Save and publish</DropdownMenuItem>
            <DropdownMenuItem>Save as template</DropdownMenuItem>
          </DropdownMenuContent>
        </DropdownMenu>
      </ButtonGroup>
    </div>
  )
}

Full width stacked

Stack actions vertically at full width in a narrow container. Use vertical orientation when long labels would not fit side by side.

"use client"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupFullWidthStacked() {
  return (
    <div className="flex flex-col items-center gap-4">
      <div className="w-full max-w-72">
        <ButtonGroup orientation="vertical" aria-label="Export format" className="w-full">
          <Button emphasis="stroke" intent="neutral">
            Export as CSV
          </Button>
          <Button emphasis="stroke" intent="neutral">
            Export as spreadsheet
          </Button>
          <Button emphasis="stroke" intent="neutral">
            Export as PDF
          </Button>
        </ButtonGroup>
      </div>
    </div>
  )
}

With icons

Group actions that pair an icon with a text label. Icons are decorative; the visible labels name each button.

"use client"

import { CopyIcon, DownloadIcon, Share2Icon } from "lucide-react"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupWithIcons() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="File actions">
        <Button emphasis="stroke" intent="neutral">
          <CopyIcon />
          Copy
        </Button>
        <Button emphasis="stroke" intent="neutral">
          <Share2Icon />
          Share
        </Button>
        <Button emphasis="stroke" intent="neutral">
          <DownloadIcon />
          Download
        </Button>
      </ButtonGroup>
    </div>
  )
}

With dot

Prefix grouped buttons with status dots. The dots are decorative and the labels carry the meaning, so color is not the only cue.

"use client"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupWithDot() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Deployment environment">
        <Button emphasis="stroke" intent="neutral">
          <span aria-hidden="true" className="size-2 rounded-full bg-success-base" />
          Production
        </Button>
        <Button emphasis="stroke" intent="neutral">
          <span aria-hidden="true" className="size-2 rounded-full bg-warning-base" />
          Staging
        </Button>
        <Button emphasis="stroke" intent="neutral">
          <span aria-hidden="true" className="size-2 rounded-full bg-faded-base" />
          Preview
        </Button>
      </ButtonGroup>
    </div>
  )
}

Disabled item

Disable one action inside a group. The disabled button uses native disabled semantics while its neighbors stay operable.

"use client"

import { Button } from "@/components/ui/button"
import { ButtonGroup } from "@/components/ui/button-group"

export function ButtonGroupDisabledItem() {
  return (
    <div className="flex flex-col items-center gap-4">
      <ButtonGroup aria-label="Export">
        <Button emphasis="stroke" intent="neutral">
          CSV
        </Button>
        <Button emphasis="stroke" intent="neutral">
          Spreadsheet
        </Button>
        <Button emphasis="stroke" intent="neutral" disabled>
          PDF
        </Button>
      </ButtonGroup>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

ButtonGroup

Joins adjacent buttons into one control. The children keep their own variants; only the corners and the shared border are managed here.

ButtonGroup props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
orientation"horizontal" | "vertical" | undefined"horizontal"Horizontal or vertical layout. The consuming layout must provide enough space for the selected orientation.
Inherited props (13)
ButtonGroup inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

ButtonGroupSeparator

Visual or semantic separation between adjacent items. It is not an operable item.

ButtonGroupSeparator props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (13)
ButtonGroupSeparator inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/button-group.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • A small set of actions that operate on the same object, such as Previous and Next, or zoom out, reset and zoom in.
  • A split button: a main action joined to an icon-only trigger that opens a dropdown menu of related variants.
  • A row of icon-only tool actions that read as one cluster in a dense toolbar or editor header.

When not to use

  • Choosing one or several options that stay selected; the group does not track pressed or selected state.
  • Unrelated actions that happen to sit next to each other; plain spacing communicates independence better than a shared border.
  • More than about four or five actions; move the rest behind a dropdown menu instead of growing the group.

Anatomy

ButtonGroup
Wrapper with role="group". Removes inner corner radii and adds a 1px gap between direct children. orientation is horizontal or vertical.
Button children
Any Button (or Button-styled trigger via asChild). Each keeps its own intent, emphasis, size, name and native activation.
ButtonGroupSeparator
Optional 1px divider between children. Presentational only; never focusable or operable.

Keyboard & interaction

  • Each button is a separate Tab stop and activates with Enter or Space; the group adds no keyboard handling.
  • Focus moves in DOM order: left to right for horizontal groups, top to bottom for vertical groups.
  • Hover, pressed, disabled and loading states come from each Button; disabling one button does not disable the group.
  • A split-button trigger opens its dropdown menu with Enter, Space or ArrowDown, following the menu's own keyboard behavior.

Responsive behavior

  • The group is w-fit and does not wrap; at narrow widths switch to orientation="vertical" or shorten labels rather than letting the row overflow.
  • A vertical group can stretch to the container (className="w-full") so each action becomes a full-width row on small screens.
  • Joined buttons sit 1px apart, so each button's own size sets the target; keep at least 24x24 CSS pixels (WCAG 2.5.8) and prefer 44x44 on touch.
  • Check reflow at 320 CSS pixels (WCAG 1.4.10): the page must not scroll horizontally because of a long group.

Content guidelines

  • Use short verbs or nouns of similar length so the joined segments look balanced: 'Previous' / 'Next', 'Day' / 'Week' / 'Month'.
  • Name the group with aria-label when its context is not already given by a nearby heading, for example 'Text alignment'.
  • Icon-only segments need an aria-label that names the action, not the icon: 'Align left', not 'Left arrow'.
  • Avoid mixing text and icon-only segments in one group unless the icon-only one is a split-button trigger with an explicit name.
  • Status dots and icons inside grouped buttons are decorative; the label names the action or the state.

Alternatives

  • Toggle group — Options with a single or multiple selection model and arrow-key navigation.
  • Dropdown menu — Several secondary actions behind one trigger when the row would overflow.
  • Tabs — Switching between panels of content rather than triggering actions.

Resources