Skip to content

Chip

SM · 950B gzip budget

A dismissible tag with a real accessible name for its remove action.

Category
Data display
Budget
sm, single-purpose control
External runtime
React / React DOM only
axe fixtureSSR rendersource scanbundle budget

Preview

Live fixture
Preview locale

Try the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.

Install

npx shadcn@latest add https://gear5-ui.vercel.app/r/chip.json

Copies the source into your project. Pulls in 1 shared registry item: cn.

New here? Set up Tailwind and import aliases first →

Source & props

Edit on GitHub ↗

Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.

import { cn } from "../lib/cn";

export interface ChipProps {
  children: React.ReactNode;
  /** Present it as removable — turns the chip into a labelled button. */
  onRemove?: () => void;
  removeLabel?: string;
  className?: string;
}

/**
 * A dismissible tag. When `onRemove` is given, the whole chip is a button
 * whose accessible name is "Remove {label}" — never a bare "×" icon with no
 * text, which announces as "button" and nothing else.
 */
export function Chip({ children, onRemove, removeLabel, className }: ChipProps) {
  const label = typeof children === "string" ? children : removeLabel;

  if (onRemove) {
    return (
      <button
        type="button"
        onClick={onRemove}
        className={cn(
          "inline-flex items-center gap-1 rounded-full border border-neutral-300 bg-white px-2.5 py-1 text-sm text-neutral-800 hover:bg-neutral-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-600 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200 dark:hover:bg-neutral-800",
          className,
        )}
        aria-label={label ? `Remove ${label}` : undefined}
      >
        <span>{children}</span>
        <span aria-hidden="true" className="text-neutral-400">
          ×
        </span>
      </button>
    );
  }

  return (
    <span
      className={cn(
        "inline-flex items-center rounded-full border border-neutral-300 bg-white px-2.5 py-1 text-sm text-neutral-800 dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-200",
        className,
      )}
    >
      {children}
    </span>
  );
}

What CI checks

Quality contract
  • Bundled, minified and gzipped against its tier budget
  • Audited by axe in the state previewed above
  • Rendered through react-dom/server with no browser globals
  • Scanned for network calls, dangerous sinks, and unguarded animation

Used by