<!-- generated by scripts/gen-docs.mjs from docs/system/icon-button.md. Edit the source and rerun. -->
# IconButton

## Description
Names a button that is only an icon once, so the one string is read aloud by a screen reader and shown on hover as the tooltip.

`import { IconButton } from "@/components/cobalt/ui/icon-button"`, source `registry/cobalt/ui/icon-button.tsx`, status `ready-with-gaps`.
Foundation: `Base UI Tooltip over shadcn button (base-luma, base)`. Traps checked: `trap/button-div`, `trap/native-control`, `trap/role-button`, `trap/button-clone`, `trap/control-height`, `trap/button-icon-name`, `trap/icon-optical-size`, `trap/icon-optical-align`, `trap/button-type`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/disabled-drops-focus`, `trap/link-wraps-button`, `trap/tooltip-disabled-trigger`, `trap/tooltip-essential`, `trap/press-delayed`, `trap/touch-tap-highlight`, `trap/motion-origin`, `trap/motion-exit-slower`.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Tooltip` root, trigger through `render`, portal, positioner and popup, opening after the provider's 400ms delay on hover and at once on keyboard focus; `Button` underneath, a native `<button>` with `type="button"`, the ghost hover fill, the `icon` squares and `pressable` | `variant="ghost"` and `size="icon"` as the defaults a caller may override; `label` written once as `aria-label` and as the tooltip's whole text; the glyph wrapped in an `aria-hidden` `contents` span, so it leaves no box and reaches the accessibility tree once; `touch-target`, a 44px hit area around the 36px square under a coarse pointer; `aria-label` and `children` removed from the props, so a second name or a text label cannot be passed; `shortcut`, keys in the shortcut map's form or the map's entry, written after the name in the tooltip as quiet text in `--tip-foreground` at 70 percent through `shortcutText` from `registry/cobalt/lib/shortcuts.ts`, in the reader's own modifiers ("Search ⌘K" on a Mac, "Search Ctrl+K" elsewhere, never caps), and on the button as `aria-keyshortcuts` through `ariaKeys` (`registry/cobalt/ui/icon-button.tsx:54`), the way Tag's tooltip writes a shortcut after the name (`~/tag/src/owner-ui/Tooltip.svelte:45`) |

## Examples
Each label is read aloud and shown on hover; the eye stays pressed while the key shows.

Real uses, 0 call sites (`rg -n "<IconButton\b" app docs/system/examples --glob '!docs/system/examples/icon-button/*'`): the showcase's theme switch is a `SegmentedControl` whose items carry their own tooltips, and the examples folder does not count.

Uses inside the registry (planned as product uses once the first screen lands on the system):
- None render it yet. `Button` names it as the fix in its development warning for an unnamed icon-only button, `registry/cobalt/ui/button.tsx:75`.
- The close buttons of a sheet and a dialog are ghost `icon-sm` Buttons named by a visually hidden label and no tooltip, `registry/cobalt/ui/sheet.tsx:594-596` and `registry/cobalt/ui/dialog.tsx:111-113`; they are the candidates to become IconButtons.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/icon-button/default.tsx` | default | Each label is read aloud and shown on hover; the eye stays pressed while the key shows |
| `docs/system/examples/icon-button/default.tsx` | variant=ghost | No fill at rest, beside a CopyButton at the end of a settings row |
| `docs/system/examples/icon-button/variant-secondary.tsx` | variant=secondary | The grey fill, for an icon button alone beside the heading of the list it adds to |
| Not applicable: the 36px square is default.tsx and variant-secondary.tsx | size=icon | The control height |
| `docs/system/examples/icon-button/in-table.tsx` | size=icon-sm | The 32px square, in a table cell and a card's corner |
| Not applicable: the same square at 40px, beside a size-lg Button | size=icon-lg | The 40px square |
| `docs/system/examples/icon-button/default.tsx` | state:on | aria-pressed holds the state and the glyph swaps in place |
| `docs/system/examples/icon-button/state-disabled.tsx` | state:disabled | The reason sits beside it; a disabled button has no tooltip |
| `docs/system/examples/icon-button/with-shortcut.tsx` | state:with-shortcut | A reading queue's arrows say their keys after their names in the tooltip, "Next paper J", and the page answers the same keys from one map |
| Not applicable: hover is reached with the pointer on any example and opens the tooltip after 400ms | state:hover | The grey fill and the name in the tooltip |
| Not applicable: focus-visible is reached with the keyboard on any example and opens the tooltip at once | state:focus-visible | The 2px ring and the name in the tooltip |
| Not applicable: pressed is the `--hover` tint while the pointer or key is down on any example | state:pressed | The press tint over the fill |
| Not applicable: expanded is reached by opening More actions in in-table.tsx or in-card.tsx, where the IconButton is the DropdownMenu trigger | state:expanded | The grey fill stays while the menu is open |
| `docs/system/examples/icon-button/in-card.tsx` | composition:Card | A ghost button in the card's corner opens its menu |
| `docs/system/examples/icon-button/in-table.tsx` | composition:Table | Each row keeps its most used action as an icon and puts the rest behind More actions |
| Not applicable: the tiles show each variant, and the sizes sit in default.tsx and in-table.tsx | matrix:variant,size | Each variant and each size |

Example: Each label is read aloud and shown on hover; the eye stays pressed while the key shows (`docs/system/examples/icon-button/default.tsx`)

```tsx
import { useState } from "react";

import { EyeIcon, EyeOffIcon } from "@/components/cobalt/icon";
import { CopyButton } from "@/components/cobalt/ui/copy-button";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { IconSwap } from "@/components/cobalt/ui/icon-swap";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/cobalt/ui/item";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

const key = "rk_2026_9f3c71ad42e8";

// Showing the key changes only this row, so it answers at once.
export default function Example() {
  const [shown, setShown] = useState(false);
  return (
    <TooltipProvider>
      <ItemGroup variant="card" className="w-full max-w-sm">
        <Item>
          <ItemContent>
            <ItemTitle>Research API key</ItemTitle>
            {/* One line in both states, so showing the key never changes the row's height. */}
            <ItemDescription>
              <span className="block truncate">
                {shown ? (
                  <span className="font-mono">{key}</span>
                ) : (
                  <>
                    Ends in <span className="font-mono">{key.slice(-4)}</span>
                  </>
                )}
              </span>
            </ItemDescription>
          </ItemContent>
          <ItemActions className="gap-1">
            <IconButton
              icon={<IconSwap show={shown ? "first" : "second"} first={<EyeOffIcon />} second={<EyeIcon />} />}
              label={shown ? "Key shown" : "Show key"}
              aria-pressed={shown}
              onClick={() => setShown((was) => !was)}
            />
            <CopyButton value={key} label="Copy key" />
          </ItemActions>
        </Item>
      </ItemGroup>
    </TooltipProvider>
  );
}
```

Example: A ghost button in the card's corner opens its menu (`docs/system/examples/icon-button/in-card.tsx`)

```tsx
import { useState } from "react";
import { toast } from "sonner";

import { DownloadIcon, MoreIcon, TrashIcon } from "@/components/cobalt/icon";
import {
  Card,
  CardAction,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/cobalt/ui/card";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/cobalt/ui/dropdown-menu";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

const papers = [
  { title: "Flood exposure in coastal mortgages", added: "Oct 14" },
  { title: "Heat stress and regional output", added: "Oct 9" },
  { title: "Carbon pricing and bank lending", added: "Sep 30" },
];

// The file is made from the rows on the page, so it downloads at once.
function download(rows: typeof papers) {
  const csv = ["title,added", ...rows.map((row) => `"${row.title}",${row.added}`)].join("\n");
  const url = URL.createObjectURL(new Blob([csv], { type: "text/csv" }));
  const link = document.createElement("a");
  link.href = url;
  link.download = "reading-list.csv";
  link.click();
  URL.revokeObjectURL(url);
}

export default function Example() {
  const [items, setItems] = useState(papers);
  return (
    <TooltipProvider>
      <Card className="w-full max-w-sm">
        <CardHeader>
          <CardTitle>Reading list</CardTitle>
          <CardDescription>Papers you added this month.</CardDescription>
          <CardAction>
            <DropdownMenu>
              <DropdownMenuTrigger
                render={<IconButton size="icon-sm" icon={<MoreIcon />} label="More actions" />}
              />
              <DropdownMenuContent align="end">
                <DropdownMenuItem disabled={items.length === 0} onClick={() => download(items)}>
                  <DownloadIcon />
                  Download as CSV
                </DropdownMenuItem>
                {/* Clearing can be undone, so it happens at once with Undo in a toast. */}
                <DropdownMenuItem
                  variant="destructive"
                  disabled={items.length === 0}
                  onClick={() => {
                    setItems([]);
                    toast("Reading list cleared", {
                      duration: 10_000,
                      action: { label: "Undo", onClick: () => setItems(papers) },
                    });
                  }}
                >
                  <TrashIcon />
                  Clear list
                </DropdownMenuItem>
              </DropdownMenuContent>
            </DropdownMenu>
          </CardAction>
        </CardHeader>
        <CardContent>
          <ul className="flex flex-col gap-2 text-sm">
            {items.map((item) => (
              <li key={item.title} className="flex justify-between gap-3">
                <span className="min-w-0 wrap-break-word">{item.title}</span>
                <span className="shrink-0 text-muted-foreground tabular-nums">{item.added}</span>
              </li>
            ))}
            {items.length === 0 && <li className="text-muted-foreground">No papers in this list.</li>}
          </ul>
        </CardContent>
      </Card>
    </TooltipProvider>
  );
}
```

Example: Each row keeps its most used action as an icon and puts the rest behind More actions (`docs/system/examples/icon-button/in-table.tsx`)

```tsx
import { useState } from "react";
import { toast } from "sonner";

import { DownloadIcon, FileSpreadsheetIcon, MoreIcon, TrashIcon } from "@/components/cobalt/icon";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/cobalt/ui/dropdown-menu";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/cobalt/ui/table";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";
import { TruncatedText } from "@/lib/cobalt/truncated-text";

type Export = { id: string; name: string; rows: number };

const exports: Export[] = [
  { id: "e1", name: "papers-retrieval.csv", rows: 1284 },
  { id: "e2", name: "advisers-2026-q3.csv", rows: 312 },
  { id: "e3", name: "funds-by-domicile.csv", rows: 96 },
];

// The file is made on the device from the export's rows, so it downloads at once.
function download(file: Export) {
  const csv = ["row", ...Array.from({ length: file.rows }, (_, i) => String(i + 1))].join("\n");
  const url = URL.createObjectURL(new Blob([csv], { type: "text/csv" }));
  const link = document.createElement("a");
  link.href = url;
  link.download = file.name;
  link.click();
  URL.revokeObjectURL(url);
}

export default function Example() {
  const [files, setFiles] = useState(exports);
  return (
    <TooltipProvider>
      <Table className="max-w-lg">
        <TableHeader>
          <TableRow>
            <TableHead>File</TableHead>
            <TableHead align="end">
              <span className="sr-only">Actions</span>
            </TableHead>
          </TableRow>
        </TableHeader>
        <TableBody>
          {files.map((file) => (
            <TableRow key={file.id}>
              <TableHead scope="row" className="w-full max-w-0">
                <TruncatedText className="block">{file.name}</TruncatedText>
                <span className="block font-normal text-muted-foreground tabular-nums">
                  {file.rows.toLocaleString("en-US")} rows
                </span>
              </TableHead>
              <TableCell align="end">
                <div className="flex justify-end">
                  <IconButton
                    size="icon-sm"
                    icon={<DownloadIcon />}
                    label={`Download ${file.name}`}
                    onClick={() => download(file)}
                  />
                  <DropdownMenu>
                    <DropdownMenuTrigger
                      render={<IconButton size="icon-sm" icon={<MoreIcon />} label={`More actions for ${file.name}`} />}
                    />
                    <DropdownMenuContent align="end">
                      <DropdownMenuItem render={<a href={`#exports/${file.id}`} />}>
                        <FileSpreadsheetIcon />
                        Open the export
                      </DropdownMenuItem>
                      {/* Deleting can be undone, so it happens at once with Undo in a toast. */}
                      <DropdownMenuItem
                        variant="destructive"
                        onClick={() => {
                          const before = files;
                          setFiles((was) => was.filter((f) => f.id !== file.id));
                          toast(`${file.name} deleted`, {
                            id: `deleted:${file.id}`,
                            duration: 10_000,
                            action: { label: "Undo", onClick: () => setFiles(before) },
                          });
                        }}
                      >
                        <TrashIcon />
                        Delete
                      </DropdownMenuItem>
                    </DropdownMenuContent>
                  </DropdownMenu>
                </div>
              </TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </TooltipProvider>
  );
}
```

## Variants

### variant
- `ghost`: the default, for an icon button in a bar, a row, a corner or a card header, no fill at rest. Used at 0 call sites; both registry close buttons are ghost.
- `secondary`: the grey fill, for an icon button standing alone with nothing to anchor it. Used at 0 call sites.

The other `Button` variants type-check and are not for it: a primary action needs a label to say what it does, so `default` and `destructive` go on a `Button` with text.

Example: No fill at rest, beside a CopyButton at the end of a settings row (`docs/system/examples/icon-button/default.tsx`)

```tsx
import { useState } from "react";

import { EyeIcon, EyeOffIcon } from "@/components/cobalt/icon";
import { CopyButton } from "@/components/cobalt/ui/copy-button";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { IconSwap } from "@/components/cobalt/ui/icon-swap";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/cobalt/ui/item";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

const key = "rk_2026_9f3c71ad42e8";

// Showing the key changes only this row, so it answers at once.
export default function Example() {
  const [shown, setShown] = useState(false);
  return (
    <TooltipProvider>
      <ItemGroup variant="card" className="w-full max-w-sm">
        <Item>
          <ItemContent>
            <ItemTitle>Research API key</ItemTitle>
            {/* One line in both states, so showing the key never changes the row's height. */}
            <ItemDescription>
              <span className="block truncate">
                {shown ? (
                  <span className="font-mono">{key}</span>
                ) : (
                  <>
                    Ends in <span className="font-mono">{key.slice(-4)}</span>
                  </>
                )}
              </span>
            </ItemDescription>
          </ItemContent>
          <ItemActions className="gap-1">
            <IconButton
              icon={<IconSwap show={shown ? "first" : "second"} first={<EyeOffIcon />} second={<EyeIcon />} />}
              label={shown ? "Key shown" : "Show key"}
              aria-pressed={shown}
              onClick={() => setShown((was) => !was)}
            />
            <CopyButton value={key} label="Copy key" />
          </ItemActions>
        </Item>
      </ItemGroup>
    </TooltipProvider>
  );
}
```

Example: The grey fill, for an icon button alone beside the heading of the list it adds to (`docs/system/examples/icon-button/variant-secondary.tsx`)

```tsx
import { useEffect, useId, useRef, useState } from "react";

import { PlusIcon } from "@/components/cobalt/icon";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { Input } from "@/components/cobalt/ui/input";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

// The guest list is part of a booking not yet sent, so a new row appears at once and takes focus.
// The button sits beside the heading, so the new rows grow under it and it never moves.
export default function Example() {
  const [guests, setGuests] = useState(["Ana Lima"]);
  const last = useRef<HTMLInputElement>(null);
  const count = useRef(guests.length);
  const heading = useId();
  useEffect(() => {
    if (guests.length > count.current) last.current?.focus();
    count.current = guests.length;
  }, [guests.length]);
  return (
    <TooltipProvider>
      <div role="group" aria-labelledby={heading} className="flex w-full max-w-xs flex-col gap-2">
        <div className="flex items-center justify-between gap-3">
          <span id={heading} className="text-sm font-medium">
            Guests
          </span>
          <IconButton
            variant="secondary"
            icon={<PlusIcon />}
            label="Add a guest"
            onClick={() => setGuests([...guests, ""])}
          />
        </div>
        {guests.map((name, index) => (
          <Input
            key={index}
            aria-label={`Guest ${index + 1}`}
            value={name}
            ref={index === guests.length - 1 ? last : undefined}
            onChange={(event) => setGuests(guests.map((was, i) => (i === index ? event.target.value : was)))}
          />
        ))}
      </div>
    </TooltipProvider>
  );
}
```

### size
- `icon`: the default, a 36px square (`--control`) with a 16px glyph. Used at 0 call sites.
- `icon-sm`: a 32px square (`--control-sm`) with the 16px glyph, the size of the registry's close buttons and of a button in a table cell. Used at 0 call sites.
- `icon-lg`: a 40px square (`--control-lg`). Used at 0 call sites.

Example: The 32px square, in a table cell and a card's corner (`docs/system/examples/icon-button/in-table.tsx`)

```tsx
import { useState } from "react";
import { toast } from "sonner";

import { DownloadIcon, FileSpreadsheetIcon, MoreIcon, TrashIcon } from "@/components/cobalt/icon";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@/components/cobalt/ui/dropdown-menu";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/cobalt/ui/table";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";
import { TruncatedText } from "@/lib/cobalt/truncated-text";

type Export = { id: string; name: string; rows: number };

const exports: Export[] = [
  { id: "e1", name: "papers-retrieval.csv", rows: 1284 },
  { id: "e2", name: "advisers-2026-q3.csv", rows: 312 },
  { id: "e3", name: "funds-by-domicile.csv", rows: 96 },
];

// The file is made on the device from the export's rows, so it downloads at once.
function download(file: Export) {
  const csv = ["row", ...Array.from({ length: file.rows }, (_, i) => String(i + 1))].join("\n");
  const url = URL.createObjectURL(new Blob([csv], { type: "text/csv" }));
  const link = document.createElement("a");
  link.href = url;
  link.download = file.name;
  link.click();
  URL.revokeObjectURL(url);
}

export default function Example() {
  const [files, setFiles] = useState(exports);
  return (
    <TooltipProvider>
      <Table className="max-w-lg">
        <TableHeader>
          <TableRow>
            <TableHead>File</TableHead>
            <TableHead align="end">
              <span className="sr-only">Actions</span>
            </TableHead>
          </TableRow>
        </TableHeader>
        <TableBody>
          {files.map((file) => (
            <TableRow key={file.id}>
              <TableHead scope="row" className="w-full max-w-0">
                <TruncatedText className="block">{file.name}</TruncatedText>
                <span className="block font-normal text-muted-foreground tabular-nums">
                  {file.rows.toLocaleString("en-US")} rows
                </span>
              </TableHead>
              <TableCell align="end">
                <div className="flex justify-end">
                  <IconButton
                    size="icon-sm"
                    icon={<DownloadIcon />}
                    label={`Download ${file.name}`}
                    onClick={() => download(file)}
                  />
                  <DropdownMenu>
                    <DropdownMenuTrigger
                      render={<IconButton size="icon-sm" icon={<MoreIcon />} label={`More actions for ${file.name}`} />}
                    />
                    <DropdownMenuContent align="end">
                      <DropdownMenuItem render={<a href={`#exports/${file.id}`} />}>
                        <FileSpreadsheetIcon />
                        Open the export
                      </DropdownMenuItem>
                      {/* Deleting can be undone, so it happens at once with Undo in a toast. */}
                      <DropdownMenuItem
                        variant="destructive"
                        onClick={() => {
                          const before = files;
                          setFiles((was) => was.filter((f) => f.id !== file.id));
                          toast(`${file.name} deleted`, {
                            id: `deleted:${file.id}`,
                            duration: 10_000,
                            action: { label: "Undo", onClick: () => setFiles(before) },
                          });
                        }}
                      >
                        <TrashIcon />
                        Delete
                      </DropdownMenuItem>
                    </DropdownMenuContent>
                  </DropdownMenu>
                </div>
              </TableCell>
            </TableRow>
          ))}
        </TableBody>
      </Table>
    </TooltipProvider>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| default | render | press, focus, hover to read the name | the glyph | test |
| hover | pointer over, under `(hover: hover)` | press; read the name in the tooltip after 400ms | the grey fill and the tooltip | by hand |
| focus-visible | keyboard focus | press with Enter or Space; the tooltip opens at once | the 2px ring, 2px outside the corner, and the tooltip | by hand |
| pressed | pointer or key down | release to act | the `--hover` tint over the fill while the pointer or key is down | by hand |
| on | `aria-pressed="true"` from the caller | press to turn it off | the glyph swapped through `IconSwap` and the `label` changed with it | test |
| disabled | `disabled` | nothing; focus skips it and no tooltip opens | half opacity and no tooltip; the pointer lands on it and does nothing, so a double-click selects no text beside it | test |
| expanded | `aria-expanded="true"` from a menu trigger | close the menu | the grey fill stays while the menu is open | screenshot |
| with-shortcut | `shortcut` given | press the keys instead, where the host binds them | the keys after the name in the tooltip, 6px after it in the tooltip's ink at 70 percent ("Next paper J"), and `aria-keyshortcuts` on the button ("J", "Meta+K" on a Mac, "Control+K" elsewhere); a sequence such as `g i` reads "G then I" and has no `aria-keyshortcuts` | test |

Example: aria-pressed holds the state and the glyph swaps in place (`docs/system/examples/icon-button/default.tsx`)

```tsx
import { useState } from "react";

import { EyeIcon, EyeOffIcon } from "@/components/cobalt/icon";
import { CopyButton } from "@/components/cobalt/ui/copy-button";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { IconSwap } from "@/components/cobalt/ui/icon-swap";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/cobalt/ui/item";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

const key = "rk_2026_9f3c71ad42e8";

// Showing the key changes only this row, so it answers at once.
export default function Example() {
  const [shown, setShown] = useState(false);
  return (
    <TooltipProvider>
      <ItemGroup variant="card" className="w-full max-w-sm">
        <Item>
          <ItemContent>
            <ItemTitle>Research API key</ItemTitle>
            {/* One line in both states, so showing the key never changes the row's height. */}
            <ItemDescription>
              <span className="block truncate">
                {shown ? (
                  <span className="font-mono">{key}</span>
                ) : (
                  <>
                    Ends in <span className="font-mono">{key.slice(-4)}</span>
                  </>
                )}
              </span>
            </ItemDescription>
          </ItemContent>
          <ItemActions className="gap-1">
            <IconButton
              icon={<IconSwap show={shown ? "first" : "second"} first={<EyeOffIcon />} second={<EyeIcon />} />}
              label={shown ? "Key shown" : "Show key"}
              aria-pressed={shown}
              onClick={() => setShown((was) => !was)}
            />
            <CopyButton value={key} label="Copy key" />
          </ItemActions>
        </Item>
      </ItemGroup>
    </TooltipProvider>
  );
}
```

Example: The reason sits beside it; a disabled button has no tooltip (`docs/system/examples/icon-button/state-disabled.tsx`)

```tsx
import { TrashIcon } from "@/components/cobalt/icon";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";

export default function Example() {
  return (
    <TooltipProvider>
      <div className="flex items-center gap-2">
        <IconButton icon={<TrashIcon />} label="Delete list" disabled />
        <p className="text-sm text-muted-foreground">Empty the list before deleting it.</p>
      </div>
    </TooltipProvider>
  );
}
```

Example: A reading queue's arrows say their keys after their names in the tooltip, "Next paper J", and the page answers the same keys from one map (`docs/system/examples/icon-button/with-shortcut.tsx`)

```tsx
import { useState } from "react";

import { ChevronDownIcon, ChevronUpIcon } from "@/components/cobalt/icon";
import { IconButton } from "@/components/cobalt/ui/icon-button";
import { TooltipProvider } from "@/components/cobalt/ui/tooltip";
import { defineShortcuts, useShortcuts } from "@/lib/cobalt/shortcuts";

// One map: the hook binds it and the buttons name it, so the keys a tooltip shows are the keys that work.
const shortcuts = defineShortcuts({
  previous: { keys: "k", label: "Previous paper" },
  next: { keys: "j", label: "Next paper" },
});

// Inert sample data: invented papers waiting to be read.
const papers = [
  "Liquidity terms in open-end real estate funds",
  "Fee breakpoints and adviser size",
  "Side pockets after the 2008 redemptions",
];

export default function Example() {
  const [at, setAt] = useState(0);
  const previous = () => setAt((i) => Math.max(0, i - 1));
  const next = () => setAt((i) => Math.min(papers.length - 1, i + 1));
  useShortcuts(shortcuts, { previous, next });
  return (
    <TooltipProvider>
      <div className="flex w-full max-w-sm items-center justify-between gap-3 text-sm">
        <div className="min-w-0">
          <p className="truncate">{papers[at]}</p>
          <p className="text-muted-foreground tabular-nums">
            Paper {at + 1} of {papers.length}
          </p>
        </div>
        <div className="flex shrink-0 items-center gap-1">
          {/* At either end the button stays where focus is, and the reason is the count beside it. */}
          <IconButton
            icon={<ChevronUpIcon />}
            label={shortcuts.previous.label}
            shortcut={shortcuts.previous}
            disabled={at === 0}
            focusableWhenDisabled
            onClick={previous}
          />
          <IconButton
            icon={<ChevronDownIcon />}
            label={shortcuts.next.label}
            shortcut={shortcuts.next}
            disabled={at === papers.length - 1}
            focusableWhenDisabled
            onClick={next}
          />
        </div>
      </div>
    </TooltipProvider>
  );
}
```

### State precedence
- Disabled and hover: disabled wins. The `hover` variant never matches a disabled element and the tooltip is disabled with the button, so no fill and no tooltip shows.
- Disabled and focus-visible: disabled wins. The button leaves the tab order, so the ring never shows.
- Hover and focus-visible: both show. The ring is an outline and the fill is a background, and the tooltip is one popup either way.
- On and hover: both show. The swapped glyph sits on the hover fill.
- Pressed and on: both show. The tint and the swapped glyph stack.
- Expanded and hover: expanded wins. The fill is already the hover fill, so hovering changes nothing.
- Expanded and focus-visible: both show. The open trigger keeps its ring and its fill.
- With-shortcut and disabled: disabled wins. No tooltip opens, so the keys do not show; the host's binding decides whether the keys still act.
- With-shortcut and hover or focus-visible: both show. The tooltip opens as it does without a shortcut, with the keys after the name.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| pointer-down to pointer-up | input | `pressable`, `--t-press` on `--curve`, from `Button` | box-shadow, background-color | `box-shadow` is not in the reduced-motion list, so the press tint is instant; the fill change stays |
| hover or focus to tooltip open, and close | announce | `popup-motion`, `--t-pop` on `--curve`, leaving in 70 percent of it, from `Tooltip` | opacity | opacity only; the name still appears |
| on to off and back, with `IconSwap` | announce | `--t-icon` on `--curve-in-out` | opacity, filter of the two glyphs in one cell | `motion-reduce:transition-none`, the glyphs switch at once |

## Props

<!-- Props generated from registry/cobalt/ui/icon-button.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `icon` | `ReactNode` |  | The glyph, from the icon barrel. |
| `label` | `string` |  | The button's accessible name and its tooltip. |
| `inset?` | `number` | `0` | How far the button sits inside the edge of the box that holds it, in pixels, such as 8 for a 28px button in a 44px bar. |
| `shortcut?` | `string \| Shortcut` |  | Keys that do the same, such as `mod+k` or the shortcut map's entry, written after the name in the tooltip. |
| `size?` | `"default" \| "sm" \| "lg" \| "icon" \| "icon-sm" \| "icon-xs" \| "icon-lg"` |  | `icon` the default; `icon-sm` a 32px square (`--control-sm`) with the 16px glyph; `icon-lg` a 40px square (`--control-lg`). |
| `variant?` | `"default" \| "secondary" \| "ghost" \| "destructive"` |  | `ghost` the default; `secondary` the grey fill. |

Also accepts every native `<button>` attribute; from Base UI: `focusableWhenDisabled`, `nativeButton`, `render`.

`icon` is the glyph, `label` is the name. `shortcut` is keys that do the same, in the shortcut map's form (`mod+k`, `j`, `g i`) or the map's entry (`shortcuts.search`); it shows them and binds nothing, so bind the same map with `useShortcuts`. `inset` is how far the button sits inside the edge of the box that holds it, in pixels, such as 8 for a 28px button in a 44px bar, so the tooltip keeps its 6px gap from the box's edge, as CopyButton's does. Every `Button` prop but `aria-label` and `children` passes through: `variant`, `size`, `disabled`, `type` (defaults to `button`), `aria-pressed`, `aria-expanded`, `onClick`, `render`. `ref` reaches the `<button>`. `className` is merged after `touch-target` and is for placement.

## Usage

### When to use
- An action is known by its glyph and sits where a label would crowd: a bar, a row, a card corner, a table cell.
- The same action repeats on every row or card, such as "More actions" or "Download".

### When not to use
- The action is read, not recognised, or it is the view's primary action. Use Button with a text label instead.
- The button stays pressed as a tool, such as bold. Use Toggle with `aria-label` and a Tooltip instead, or IconButton with `aria-pressed` when it is a per-item state such as a key shown in full.
- The action is slow and must report itself. Use StateButton instead; a settling glyph has no label to hold its box.
- The press navigates. Use a link styled with `buttonVariants`, or BackLink instead.
- The press copies a value or saves a thing. Use CopyButton or SaveToggle instead.

### Rules
- `rule/icon-button-no-second-tooltip`: When an icon button needs more than its name, put that text beside it as visible copy, instead of wrapping it in a second `Tooltip` that says more than `label`, because a tooltip is hover-only and touch has no hover, so a sentence that lives only there is never seen on a phone. Evidence: principle input: touch has no hover, so a tooltip is never the only place for a fact; principle heuristic: recognition rather than recall, the name is enough to recognise the glyph. Check: review of every IconButton inside a Tooltip or with a `title`.
  - Don't: `<Tooltip><TooltipTrigger render={<IconButton icon={<TrashIcon />} label="Delete" />} /><TooltipContent>Deletes the list for everyone</TooltipContent></Tooltip>`
  - Do: `<IconButton icon={<TrashIcon />} label="Delete list" />`
- `rule/icon-button-disabled-reason-visible`: When an icon button is `disabled`, write the reason as visible text in the same row, instead of putting it in `label`, because a disabled trigger opens no tooltip and takes no focus, so keyboard and touch users never see it. Evidence: principle platform: a disabled button takes no hover and leaves the tab order, so nothing on it can be read; principle heuristic: visibility of system status, the reason is on screen. Check: review of every `disabled` IconButton for a sibling text.
  - Don't: `<IconButton icon={<TrashIcon />} label="Delete list (empty it first)" disabled />`
  - Do: `<IconButton icon={<TrashIcon />} label="Delete list" disabled /> <p className="text-sm text-muted-foreground">Empty the list before deleting it.</p>`
- `rule/icon-button-ghost-in-rows`: When icon buttons share a bar, a row or a corner, keep `variant="ghost"` (the default) and give `variant="secondary"` only to one that stands alone, because a filled square in a row of squares reads as the selected one. Evidence: app 2/2 icon-only buttons in the registry are ghost, `registry/cobalt/ui/sheet.tsx:594` and `registry/cobalt/ui/dialog.tsx:111`; person D18, only an on state is a filled control. Check: review of every row of IconButtons.
  - Don't: `<IconButton variant="secondary" icon={<SearchIcon />} label="Search" /> <IconButton variant="secondary" icon={<BellIcon />} label="Notifications" />`
  - Do: `<IconButton icon={<SearchIcon />} label="Search" /> <IconButton icon={<BellIcon />} label="Notifications" />`
- `rule/icon-button-on-state-through-aria-pressed`: When an icon button stays on, pass `aria-pressed`, change `label` with the state and swap the glyph through `IconSwap`, instead of swapping `icon` between two elements, because `aria-pressed` is how the state is announced and two glyphs in one fixed cell never move the box. Evidence: principle wcag: 4.1.2 Name, role, value, the state is exposed through the attribute; principle heuristic: visibility of system status, the glyph and the name agree with the state. Check: test `icon-button.test.tsx` renders `aria-pressed` through to the button; review of every IconButton whose `icon` is a ternary.
  - Don't: `<IconButton icon={shown ? <EyeOffIcon /> : <EyeIcon />} label="Show key" onClick={toggle} />`
  - Do: `<IconButton icon={<IconSwap show={shown ? "first" : "second"} first={<EyeOffIcon />} second={<EyeIcon />} />} label={shown ? "Key shown" : "Show key"} aria-pressed={shown} onClick={toggle} />`

- `rule/icon-button-shortcut-from-the-map`: When an icon button's action also answers a key, pass the shortcut map's entry as `shortcut` and bind the same map with `useShortcuts`, instead of writing the keys into `label` or setting a `Kbd` beside the button, because `shortcut` writes the keys after the name in the reader's own modifiers and gives them to a screen reader as `aria-keyshortcuts`, while keys in `label` become part of the accessible name, read as "Search, place of interest sign K", and keys typed by hand drift from the keys the page answers. Evidence: single use docs/system/examples/icon-button/with-shortcut.tsx:26, the queue binds the map its two buttons name; measured "Next paper J" with `aria-keyshortcuts="J"` on keyboard focus at 1440, `.design-system/evidence/icon-button/shortcut-tooltip-1440.png`; principle wcag: 4.1.2 Name, role, value, the name stays the action. Check: test `icon-button.test.tsx` renders the keys after the name and `aria-keyshortcuts`; review of every `label` for a key symbol.
  - Don't: `<IconButton icon={<SearchIcon />} label="Search (⌘K)" />`
  - Do: `<IconButton icon={<SearchIcon />} label="Search" shortcut={shortcuts.search} />`

### Content
- Follows `rule/writing-tooltip-is-the-name`.
- Follows `rule/writing-button-verb`.
- `rule/icon-button-label-names-the-action`: When `label` is written, name what the press does, a verb and its object such as "Copy link", or the place it opens such as "Settings", instead of the glyph such as "Gear" or "Bell", because the label is the whole accessible name and the whole tooltip, and a glyph's name says nothing about the outcome. Evidence: person D11; principle wcag: 4.1.2 Name, role, value, the name describes the purpose. Check: lint copy/max-chars on the tooltip slot (scripts/copy-check.mjs); review of every `label`.
  - Don't: `<IconButton icon={<BellIcon />} label="Bell" />`
  - Do: `<IconButton icon={<BellIcon />} label="Notifications" />`

### Anti-slop
- `rule/icon-button-no-text-children`: When a button has a visible text label, render `Button` instead of `IconButton`, because a tooltip that repeats a label people can already read is noise, and the props omit `children` so text cannot be passed. Evidence: principle heuristic: aesthetic and minimalist design, one name per control; principle platform: a tooltip supplements a control, it never repeats its text. Check: lint through the props type, which omits `children`, so `pnpm typecheck` fails the violation.
  - Don't: `<IconButton icon={<PlusIcon />} label="New item">New item</IconButton>`
  - Do: `<Button>New item</Button>`
- `rule/icon-button-glyph-sized-by-the-square`: When an icon button changes size, pass `size="icon-sm"` or `size="icon-lg"` and let the square size the glyph, instead of a `size` or `width` prop on the icon, because `Button` sizes any glyph without a `size-*` class to its square, and one rule then sizes every glyph. Evidence: person D27; principle heuristic: consistency and standards, the glyph size follows the control size. Check: lint rule/component-override on the icon (scripts/check-system.mjs); review.
  - Don't: `<IconButton size="icon-lg" icon={<CopyIcon size={20} />} label="Copy link" />`
  - Do: `<IconButton size="icon-lg" icon={<CopyIcon />} label="Copy link" />`

### Limits
- `rule/icon-button-row-max`: When more than 8 icon buttons would share one row at 390px, keep 7 and put the rest behind one "More actions" IconButton that opens a `DropdownMenu`, because at 9 the row leaves the viewport (right 396px > 390px) in a 310px column with a 4px gap. Evidence: measured 9 squares overflow at 396px, .design-system/evidence/icon-button/grow-390.json; principle heuristic: recognition rather than recall, a row past 7 glyphs has to be scanned. Check: probe `.design-system/scripts/grow-actions.mjs icon-button` on the showcase at 390.
  - Don't: `{actions.map((a) => <IconButton key={a.label} icon={a.icon} label={a.label} />)}` with 9 actions
  - Do: `{actions.slice(0, 7).map((a) => <IconButton key={a.label} icon={a.icon} label={a.label} />)} <DropdownMenu><DropdownMenuTrigger render={<IconButton icon={<MoreHorizontalIcon />} label="More actions" />} />{/* the rest */}</DropdownMenu>`

## Accessibility
Rests on `<button>` from Base UI `Button`, named by `aria-label`, inside a Base UI `Tooltip` trigger.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the button | focuses it, shows the ring and opens the tooltip | the button | by hand |
| Enter or Space | the button | presses it | the button, unless the action moves focus | by hand |
| Escape | the button, tooltip open | closes the tooltip | the button | by hand |
| Tab | a disabled button | skips it; no tooltip | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | button | `label`, as `aria-label` | `disabled`; `aria-pressed` and `aria-expanded` from the caller; `aria-keyshortcuts` from `shortcut` | the name and role on focus, with pressed or not pressed when `aria-pressed` is set, and the keys where the screen reader reads `aria-keyshortcuts` | test |
| glyph | none | hidden, `aria-hidden="true"` on the `contents` span | none | nothing | test |
| tooltip | tooltip | `label` | open after 400ms on hover, at once on focus; closed on Escape or leave; the keys of `shortcut` in an `aria-hidden` span | not read a second time: the trigger gets no `aria-describedby` | by hand |

Contrast: the ghost glyph is the ink on the page, measured 19.8 to 1 in the showcase's example frame, .design-system/evidence/icon-button/grow-390.json. The secondary fill is the Button's, 17.03 to 1 as measured on the Pill's grey fill.

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--control-sm`, `--control`, `--control-lg`, `--touch`, `--r-lg`, `--t-press`, `--curve`, `--ring` |
| ghost | hover and expanded | `--muted`, `--foreground` |
| secondary | rest | `--secondary`, `--secondary-foreground` |
| secondary | hover | `--muted-hover` |
| glyph | all | `--foreground`, 16px (`size-4`) |
| tooltip | open | `--tip` fill, `--tip-foreground` text, `--t-pop`, `--curve` |
| tooltip keys | open, with `shortcut` | `--tip-foreground` at 70 percent, computed 9.1 to 1 on `--tip` in light and 7.8 to 1 in dark |

## Related
- Button: a button with a text label, which an icon button is not.
- Toggle: a button that stays pressed as a tool.
- StateButton: a button that reports a slow action in place.
- Tooltip: the name shown on hover, which IconButton wires for you.
- IconSwap: two glyphs in one fixed cell, for an icon button that stays on.
- Keyboard shortcuts: the one map whose keys `shortcut` names and `useShortcuts` binds.
