Components
Button group
Joined button group for toolbars, split actions, and segmented controls.
Composition
Joined actions
- <ButtonGroup>
- <ButtonGroupText />
- primary action
- <Button />
- secondary action
- <Button />
Installation
The Control UI source installs this component from src/registry/sources/control-ui/ui/button-group.tsx.
npx shadcn@latest add https://control-ui.dev/r/button-group.jsonDependencies
Raw code
Primary installed source
"use client";
import type { ComponentProps, CSSProperties } from "react";import type { HoverIndicator } from "@/components/control-ui/control-props";import type { ControlSize } from "@/components/control-ui/control-variants";import { TrackHighlight } from "@/components/control-ui/extensions/track-highlight";import type { ButtonGroupKnobStyle } from "@/components/control-ui/knob-contracts/button-group-knobs";import { cn } from "@/components/control-ui/lib/cn";import { useSkin } from "@/components/control-ui/skin-provider";
import { ButtonTrackContext, buttonTrackStructureClasses } from "@/components/control-ui/ui/button";
export type ButtonGroupTextProps = Omit< ComponentProps<"div"> & { size?: ControlSize; }, "style"> & { style?: CSSProperties & ButtonGroupKnobStyle };
export type ButtonGroupProps = ComponentProps<"div"> & { orientation?: "horizontal" | "vertical"; indicator?: HoverIndicator;} & { style?: CSSProperties & ButtonGroupKnobStyle };
export function ButtonGroup({ orientation = "horizontal", indicator, className, children, ...props }: ButtonGroupProps) { const skin = useSkin(); const resolvedIndicator = indicator ?? skin.indicators?.["button-group"] ?? "none"; const tracksHover = resolvedIndicator === "hover"; return ( <ButtonTrackContext value={tracksHover}> {/* biome-ignore lint/a11y/useSemanticElements: a segmented control is a labelled group, not a fieldset form group. */} <div role="group" data-control-ui="button-group" data-control-family="button-group" data-slot="root" data-orientation={orientation} data-join={skin.buttonGroupJoin ?? "frame"} data-track={resolvedIndicator} className={cn(buttonTrackStructureClasses, "inline-flex w-fit items-stretch data-[orientation=vertical]:flex-col", className)} {...props} > {children} {tracksHover ? <TrackHighlight className="z-0" /> : null} </div> </ButtonTrackContext> );}
export function ButtonGroupText({ size = "sm", className, ...props }: ButtonGroupTextProps) { return ( <div data-control-ui="button-group" data-control-family="button-group" data-slot="text" data-size={size} className={cn("inline-flex items-center whitespace-nowrap", className)} {...props} /> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-button-group-radius | <length-percentage> | var(--nest-radius, var(--radius-control)) |
--cui-button-group-shadow | * | inset 0 0 0 var(--control-rim-width) var(--control-rim), var(--shadow-sm) |
--cui-button-group-text-background | <color> | var(--control-fill) |
--cui-button-group-text-foreground | <color> | var(--muted-foreground) |
--cui-button-group-separator-color | <color> | var(--border) |