COMPONENTS/ACTIONS

Action bar.

Actions for the current selection.

In practice

3 selected

Shown when selectedCount is positive. Supply action buttons and onClear. A labeled region groups actions without imposing toolbar keyboard behavior.

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 { ActionBar, Button, Select } from "@chlohal/coal-ui";
export default function Example() {
    const [message, setMessage] = React.useState("");
    const notice = <p role="status">{message}</p>;
    const [saved, setSaved] = React.useState(false);
    return (<div>
          {saved ? (<Button variant="outline" onClick={() => setSaved(false)}>
              Select 3 items
            </Button>) : (<ActionBar selectedCount={3} onClear={() => setSaved(true)}>
              <Button size="sm" variant="outline" onClick={() => {
                setMessage("3 items archived.");
                setSaved(true);
            }}>
                Archive
              </Button>
            </ActionBar>)}
          {notice}
        </div>);
}

Source

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

packages/react/src/action-bar.tsx
"use client";
import * as React from "react";
import { cn } from "./internal.js";
export type ActionBarProps = React.ComponentPropsWithRef<"div"> & {
  selectedCount: number;
  onClear?: () => void;
};
export function ActionBar({
  selectedCount,
  onClear,
  children,
  className,
  ...props
}: ActionBarProps) {
  if (selectedCount < 1) return null;
  return (
    <div
      role="region"
      aria-label="Selection actions"
      className={cn("coal-action-bar", className)}
      {...props}
    >
      <span role="status">{selectedCount} selected</span>
      {children}
      {onClear && (
        <button type="button" onClick={onClear}>
          Clear selection
        </button>
      )}
    </div>
  );
}

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.