Button Group

Grouped controls for adjacent actions, segmented selection, labels, separators, and toolbar layouts.

Button Group

Grouped controls for adjacent actions, segmented selection, labels, separators, and toolbar layouts.

The ButtonGroup shell snaps random siblings into one toolbar — Edit, Preview, and Publish share a single rounded frame, collapse their inner borders into shared dividers, and pull their text down to a muted tone that darkens on hover. Add an IconButton for an overflow affordance, drop in ButtonGroupText for a label, or swap the whole thing for a SegmentedControl when the group is a single-choice toggle.

Installation

Install the component with the Craft-UI Blocks CLI — it drops button-group.tsx into your project and wires up its runtime dependencies:

npx mvpblocks add button-group
pnpm dlx mvpblocks add button-group
yarn dlx mvpblocks add button-group
bunx mvpblocks add button-group

File Structure

The CLI saves the component to your project's components/ui folder:

Import it from @/components/ui/button-group.

Usage

"use client";

import { MoreHorizontalIcon } from "lucide-react";

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

export function ButtonGroupDemo() {
  return (
    <ButtonGroup aria-label="Project actions" size="sm">
      <Button>Edit</Button>
      <Button>Preview</Button>
      <Button>Publish</Button>
      <IconButton aria-label="More project actions">
        <MoreHorizontalIcon />
      </IconButton>
    </ButtonGroup>
  );
}

Every child inside ButtonGroup is connected by default: radii flatten, borders merge into shared dividers, and the group reads the size once and applies it to each control. Reach for ButtonGroupText to anchor a label, ButtonGroupSeparator to break a section, or ButtonGroupItems when you want a shared hover frame instead of dividers.

Theming

The group ships its own Iconiq token set, scoped to the component root and mapped onto the standard shadcn variable names (--color-background, --color-foreground, --color-border, --color-muted, and so on), so colors resolve with no separate theme install. In light mode the tokens are a white surface with #111111 ink and #e3e7ec hairlines; in dark mode they flip to a #111111 surface with #f6f3ec ink and #2b2a25 hairlines, driven entirely by dark: overrides on the same variables. The token block is applied once at the ButtonGroup (and SegmentedControl) root, and connected children opt out via shouldApplyTheme, so nested buttons never repeat the full set.

Each action picks its surface from actionButtonVariants: default sits on the page background with muted text that darkens to foreground on hover, outline matches it with a hairline border, ghost is transparent until hover, and destructive uses a soft text-destructive tint with a destructive/10 hover wash. The shell itself comes from buttonGroupVariants, which merges adjacent children with [&>[data-slot]~[data-slot]] selectors — horizontal groups gain a border-l divider, vertical groups a border-t. The ripple is drawn with bg-current, so it always inherits the resolved variant text color in both modes without a second palette.

Animations

  • Ripple: a pointer ripple is drawn at the press point, sized to the farthest corner, colored with the inherited bg-current. It blooms from scale: 0 / opacity: 0.16 to scale: 1 / opacity: 0 over 0.55s ease-[0.22, 1, 0.36, 1], then removes itself on onAnimationComplete. Set disableRipple on the group or an individual control to keep only the hover/active feedback.
  • Shared hover frame (ButtonGroupItems with showDividers={false}): a single motion.span frame springs to the hovered item's measured rect on a 420 / 34 / 0.8 spring with a bg-muted/45 fill. It is tracked through a ResizeObserver plus a window resize listener so it stays glued to the item as the group reflows, and clears on pointer-leave or when focus leaves the group.
  • Dividers (showDividers): adjacent items gain a border-r (except the last), the outer corners round to 7px, and hover paints a bg-muted wash per item instead of a moving frame.
  • Segmented indicator (SegmentedControl): the selected segment is a Motion layoutId pill (bg-accent) that springs between positions on a 170 / 21 / 0.9 spring with bounce: 0, scoped to a per-instance layoutId inside a LayoutGroup so multiple controls never cross-animate. A bg-muted/40 hover overlay fades in over 0.24s, the label steps between opacity: 1 and 0.72 over 0.28s, and each segment taps to scale: 0.96.
  • Keyboard: the segmented control is a roving-tabindex radiogroup — ArrowLeft/ArrowRight/ArrowUp/ArrowDown move and select, Home/End jump to the ends, and the horizontal axis mirrors for RTL layouts.

Motion and interaction

  • Each export keeps the same tactile feel, but the default presentation is now much more compact and toolbar-like.
  • Button, IconButton, and ButtonGroupItems all default to muted text that darkens on hover, which better matches compact shadcn-style controls.
  • ButtonGroup applies embedded theme tokens once at the group root so nested buttons do not repeat the full token block.
  • The ButtonGroup wrapper uses the exported buttonGroupVariants CVA recipe, while existing motion-powered controls keep their ripple and shared-hover behavior.
  • Ripple feedback can now be turned off per surface, which is useful when you want a quieter desktop toolbar feel.
  • SegmentedControl keeps motion focused on selection changes rather than entrance effects, so the control feels faster and less oversized.

Props

Button

Prop

Type

IconButton

Prop

Type

ButtonGroup

Prop

Type

ButtonGroupText

Prop

Type

ButtonGroupSeparator

Prop

Type

ButtonGroupItems

Prop

Type

SegmentedControl

Prop

Type

Registry Bundle

Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: @base-ui/react, motion, class-variance-authority.

Embedded Iconiq theme tokens ship inside the component, so colors resolve without a separate theme install. This page documents the Base UI install only, because Radix UI does not ship a separate button-group primitive.

Contact

If you find any bug or issue, feel free to raise an issue.

Last updated on