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-grouppnpm dlx mvpblocks add button-groupyarn dlx mvpblocks add button-groupbunx mvpblocks add button-groupFile 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 fromscale: 0/opacity: 0.16toscale: 1/opacity: 0over0.55sease-[0.22, 1, 0.36, 1], then removes itself ononAnimationComplete. SetdisableRippleon the group or an individual control to keep only the hover/active feedback. - Shared hover frame (
ButtonGroupItemswithshowDividers={false}): a singlemotion.spanframe springs to the hovered item's measured rect on a420 / 34 / 0.8spring with abg-muted/45fill. It is tracked through aResizeObserverplus a windowresizelistener 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 aborder-r(except the last), the outer corners round to7px, and hover paints abg-mutedwash per item instead of a moving frame. - Segmented indicator (
SegmentedControl): the selected segment is a MotionlayoutIdpill (bg-accent) that springs between positions on a170 / 21 / 0.9spring withbounce: 0, scoped to a per-instancelayoutIdinside aLayoutGroupso multiple controls never cross-animate. Abg-muted/40hover overlay fades in over0.24s, the label steps betweenopacity: 1and0.72over0.28s, and each segment taps toscale: 0.96. - Keyboard: the segmented control is a roving-tabindex
radiogroup—ArrowLeft/ArrowRight/ArrowUp/ArrowDownmove and select,Home/Endjump 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, andButtonGroupItemsall default to muted text that darkens on hover, which better matches compact shadcn-style controls.ButtonGroupapplies embedded theme tokens once at the group root so nested buttons do not repeat the full token block.- The
ButtonGroupwrapper uses the exportedbuttonGroupVariantsCVA 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.
SegmentedControlkeeps 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