Button group

Adjacent buttons joined into one control — AppKit’s segmented push buttons, apple.com’s paired actions.

controls

Apple: Buttons

· Base UI: element

Joined buttons

import { ArrowLeft01Icon, ArrowRight01Icon } from "@hugeicons/core-free-icons"

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

export default function ButtonGroupBasic() {
  return (
    <div className="flex flex-wrap items-center gap-6">
      <ButtonGroup aria-label="Navigate">
        <Button variant="gray" aria-label="Back">
          <Icon icon={ArrowLeft01Icon} weight="semibold" />
        </Button>
        <Button variant="gray" aria-label="Forward">
          <Icon icon={ArrowRight01Icon} weight="semibold" />
        </Button>
      </ButtonGroup>
      <ButtonGroup aria-label="View">
        <Button variant="gray" size="small">
          Day
        </Button>
        <Button variant="gray" size="small">
          Week
        </Button>
        <Button variant="gray" size="small">
          Month
        </Button>
      </ButtonGroup>
    </div>
  )
}

Install

From the registry this site publishes, with dependencies resolved by the CLI.

npx shadcn@latest add https://applecn.vercel.app/r/button-group.json

Source

packages/ui/src/components/button-group.tsx

import { cn } from "cn"
import type { ComponentProps } from "react"

/**
 * A button group: adjacent buttons joined into one control, as AppKit's segmented push
 * buttons and apple.com's paired actions. Only the outer corners keep the platform's radius;
 * a hairline separates the segments. Give it an `aria-label` that names the set.
 */
function ButtonGroup({
  className,
  orientation = "horizontal",
  ...props
}: ComponentProps<"div"> & { orientation?: "horizontal" | "vertical" }) {
  return (
    <div
      role="group"
      data-slot="button-group"
      data-orientation={orientation}
      className={cn(
        "inline-flex w-fit items-stretch [&>*]:relative [&>*:focus-visible]:z-10",
        orientation === "horizontal"
          ? "[&>*:not(:first-child)]:-ms-px [&>*:not(:first-child)]:rounded-s-none [&>*:not(:first-child)]:border-s-[0.5px] [&>*:not(:first-child)]:border-s-separator [&>*:not(:last-child)]:rounded-e-none"
          : "flex-col [&>*:not(:first-child)]:-mt-px [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-[0.5px] [&>*:not(:first-child)]:border-t-separator [&>*:not(:last-child)]:rounded-b-none",
        className
      )}
      {...props}
    />
  )
}

export { ButtonGroup }