COMPONENTS/ACTIONS

Button group.

Related actions, kept together.

In practice

Use aria-label to describe the group. Each button remains independently focusable.

Installation

Install Coal once. Components and TypeScript declarations are included. React 19 and React DOM 19 are peer dependencies.

Terminal · local package
npm install http://localhost:3100/downloads/chlohal-coal-ui-0.5.0.tgz

This installs the local package. It is not yet published on npm. See installation for stylesheet setup and integration.

Usage

example.tsx
"use client";
import * as React from "react";
import "@chlohal/coal-ui/styles.css";
import { Copy } from "lucide-react";
import { Button, ButtonGroup } from "@chlohal/coal-ui";
export default function Example() {
    const [message, setMessage] = React.useState("");
    const notice = <p role="status">{message}</p>;
    return (<div>
          <ButtonGroup aria-label="Project actions">
            <Button size="sm" variant="ghost" onClick={async () => {
            try {
                await navigator.clipboard.writeText(window.location.href);
                setMessage("Link copied.");
            }
            catch {
                setMessage("Copy the address from your browser.");
            }
        }}>
              Share
            </Button>
            <Button size="sm" variant="outline" onClick={() => setMessage("Project duplicated.")}>
              <Copy />
              Duplicate
            </Button>
          </ButtonGroup>
          {notice}
        </div>);
}

Source

The original Coal implementation. Use the package export to integrate it.

packages/react/src/button-group.tsx
import * as React from "react";
import { cn } from "./internal.js";
export type ButtonGroupProps = React.ComponentPropsWithRef<"div">;
export function ButtonGroup({ className, ...props }: ButtonGroupProps) {
  return (
    <div
      role="group"
      className={cn("coal-button-group", className)}
      {...props}
    />
  );
}

Accessibility checklist

  • Provide an accessible name for controls, including icon-only buttons.
  • Check keyboard navigation, visible focus and disabled states in your application.
  • Do not rely on color alone to communicate status.