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

## Description
Starts an action now: the one primary action of a view, and the grey, ghost or red forms for the rest.

`import { Button, buttonVariants } from "@/components/cobalt/ui/button"`, source `registry/cobalt/ui/button.tsx`, status `ready-with-gaps`.
Foundation: `shadcn button (base-luma, base)`. Traps checked: `trap/button-div`, `trap/native-control`, `trap/role-button`, `trap/link-as-button`, `trap/button-clone`, `trap/control-height`, `trap/button-icon-name`, `trap/icon-optical-size`, `trap/icon-optical-align`, `trap/button-type`, `trap/submit-repeat`, `trap/weight-shift`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/disabled-drops-focus`, `trap/link-wraps-button`, `trap/loading-layout-shift`, `trap/loading-label-swap`, `trap/button-label-wrap`, `trap/tooltip-disabled-trigger`, `trap/press-delayed`, `trap/touch-tap-highlight`.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Base UI `Button`: a native `<button>` with `type="button"` by default, `render` for composition, `focusableWhenDisabled`, `nativeButton` | `pressable` (the `--hover` press tint on the press duration), heights from `--control-sm`, `--control`, `--control-lg` as `min-h` so text zoom grows the box, hover fills from `--primary-hover` and `--muted-hover`, the `destructive` light red background with red text, a development-only check that a button has an accessible name A label wider than its container wraps inside the box, `max-w-full` and `text-center` in place of `white-space: nowrap`, so a translated label never runs out of a 320px column; `shrink-0` keeps it on one line whenever the row has room. A wrapped label keeps a one-line label's room above and below it, `py-[calc((var(--control)-1lh-2px)/2)]` at each size, half of what the control's height leaves around one line inside the 1px border, as StateButton does: at 320 a two-line label sat in a 36px box with its words 3px from the edges, and now takes a 46px box with 8px above and below them, while every one-line button, anchor and glyph button on the docs measured the same height before and after (205 buttons at 1440 and at 320, 2026-10-17). The glyph trims are logical, `ps` and `pe`, so right-to-left text trims the right side (`docs/research/2026-10-16-break-ui-inputs.md`). |

## Examples
A form's footer with Cancel and the one primary action, each variant and size, and a link drawn as a button.

Real uses, 0 call sites (`rg -n "<Button\b" app docs/system/examples --glob '!docs/system/examples/button/*'`): the showcase chrome renders no Button of its own yet, and the examples folder does not count.

Uses inside the registry, which other components build on (planned as product uses once the first screen lands on the system):
- The close button of a sheet, ghost `icon-sm`, `registry/cobalt/ui/sheet.tsx:594-596`.
- The close button of a dialog, ghost `icon-sm`, `registry/cobalt/ui/dialog.tsx:111-113`.
- The action of an alert dialog, the default fill, `registry/cobalt/ui/alert-dialog.tsx:172`.
- The cancel of an alert dialog, rendered through `render` with the caller's variant, `registry/cobalt/ui/alert-dialog.tsx:187`.
- The next step of an empty state, `secondary`, `registry/cobalt/ui/empty.tsx:111`.
- The icon-only button, ghost `icon` inside a tooltip, `registry/cobalt/ui/icon-button.tsx:50-52`.
- The settling button, which wraps it to report its status in place, `registry/cobalt/ui/state-button.tsx:140`.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/button/default.tsx` | default | Cancel first, then the one primary action, which submits the form; on a phone the primary sits on top |
| `docs/system/examples/button/variant-default.tsx` | variant=default | The one primary action of a view, in the accent |
| `docs/system/examples/button/size-default.tsx` | size=default | 36px, the height every control in a row shares |
| `docs/system/examples/button/variant-secondary.tsx` | variant=secondary | The grey fill, for every action but the primary one |
| `docs/system/examples/button/variant-ghost.tsx` | variant=ghost | No fill at rest, for an action repeated on every row |
| `docs/system/examples/button/variant-destructive.tsx` | variant=destructive | Red text on a light red background, and a confirmation first |
| `docs/system/examples/button/size-sm.tsx` | size=sm | 32px, for a button beside a field or in a header |
| `docs/system/examples/button/size-lg.tsx` | size=lg | 40px, for the last action of a phone flow |
| Not applicable: a button that is only an icon is an IconButton, whose examples show the 36px square with its name in a tooltip | size=icon | The 36px square |
| Not applicable: the same square at 32px, the close button of every dialog and sheet | size=icon-sm | The 32px square |
| Not applicable: the inset square lives inside another box, so the copy button's chip example shows it | size=icon-xs | The 28px square inset 4px inside a 36px chip, its 6px corner concentric with the chip's 10px |
| Not applicable: the same square at 40px, beside a size-lg button | size=icon-lg | The 40px square |
| `docs/system/examples/button/state-disabled.tsx` | state:disabled | Disabled until the field is filled, with the reason beside it |
| `docs/system/examples/button/state-expanded.tsx` | state:expanded | The fill stays while the button's menu is open |
| Not applicable: hover is reached with the pointer on any example | state:hover | The grey fill or the darker accent, on the press duration |
| Not applicable: focus-visible is reached with the keyboard on any example | state:focus-visible | The 2px ring outside the corner |
| 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 |
| `docs/system/examples/button/default.tsx` | composition:Field | Cancel and Apply under a labelled select; Apply is the form's submit and narrows the papers below |
| `docs/system/examples/button/as-link.tsx` | composition:Anchor | A press that goes to another page is an anchor drawn through `buttonVariants` |
| Not applicable: the tiles show each variant and each size | matrix:variant,size | Each variant and each size |

A press that stays on the page answers at once; one that reaches a server goes through StateButton (size-default.tsx, size-lg.tsx). A footer in a dialog is the Dialog's own example.

Example: Cancel first, then the one primary action, which submits the form; on a phone the primary sits on top (`docs/system/examples/button/default.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import { Field, FieldLabel } from "@/components/cobalt/ui/field";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";

const papers = [
  { title: "Liquidity transformation in open-end bond funds", year: 2026 },
  { title: "Fee dispersion among registered investment advisers", year: 2025 },
  { title: "Flood exposure in coastal mortgages", year: 2023 },
  { title: "Carbon pricing and bank lending", year: 2021 },
];
const years = ["2021", "2022", "2023", "2024", "2025", "2026"].map((year) => ({ value: year, label: year }));

// The filter narrows papers already on the page, so applying it answers at once and needs no spinner.
export default function Example() {
  const [applied, setApplied] = useState("2021");
  const [draft, setDraft] = useState(applied);
  const shown = papers.filter((paper) => paper.year >= Number(applied));
  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <form
        className="flex flex-col gap-4"
        onSubmit={(event) => {
          event.preventDefault();
          setApplied(draft);
        }}
      >
        <Field>
          <FieldLabel>Published from</FieldLabel>
          <Select items={years} value={draft} onValueChange={(value) => setDraft(value ?? draft)}>
            <SelectTrigger className="w-full">
              <SelectValue />
            </SelectTrigger>
            <SelectContent>
              {years.map((year) => (
                <SelectItem key={year.value} value={year.value}>
                  {year.label}
                </SelectItem>
              ))}
            </SelectContent>
          </Select>
        </Field>
        {/* Button is type="button" unless told otherwise, so Cancel never submits the form. */}
        <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
          <Button variant="secondary" onClick={() => setDraft(applied)}>
            Cancel
          </Button>
          <Button type="submit">Apply</Button>
        </div>
      </form>
      <ul className="flex flex-col gap-2 text-sm">
        {shown.map((paper) => (
          <li key={paper.title} className="flex justify-between gap-3">
            <span className="min-w-0 wrap-break-word">{paper.title}</span>
            <span className="shrink-0 text-muted-foreground tabular-nums">{paper.year}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

Example: Cancel and Apply under a labelled select; Apply is the form's submit and narrows the papers below (`docs/system/examples/button/default.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import { Field, FieldLabel } from "@/components/cobalt/ui/field";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/cobalt/ui/select";

const papers = [
  { title: "Liquidity transformation in open-end bond funds", year: 2026 },
  { title: "Fee dispersion among registered investment advisers", year: 2025 },
  { title: "Flood exposure in coastal mortgages", year: 2023 },
  { title: "Carbon pricing and bank lending", year: 2021 },
];
const years = ["2021", "2022", "2023", "2024", "2025", "2026"].map((year) => ({ value: year, label: year }));

// The filter narrows papers already on the page, so applying it answers at once and needs no spinner.
export default function Example() {
  const [applied, setApplied] = useState("2021");
  const [draft, setDraft] = useState(applied);
  const shown = papers.filter((paper) => paper.year >= Number(applied));
  return (
    <div className="flex w-full max-w-md flex-col gap-6">
      <form
        className="flex flex-col gap-4"
        onSubmit={(event) => {
          event.preventDefault();
          setApplied(draft);
        }}
      >
        <Field>
          <FieldLabel>Published from</FieldLabel>
          <Select items={years} value={draft} onValueChange={(value) => setDraft(value ?? draft)}>
            <SelectTrigger className="w-full">
              <SelectValue />
            </SelectTrigger>
            <SelectContent>
              {years.map((year) => (
                <SelectItem key={year.value} value={year.value}>
                  {year.label}
                </SelectItem>
              ))}
            </SelectContent>
          </Select>
        </Field>
        {/* Button is type="button" unless told otherwise, so Cancel never submits the form. */}
        <div className="flex flex-col-reverse gap-2 sm:flex-row sm:justify-end">
          <Button variant="secondary" onClick={() => setDraft(applied)}>
            Cancel
          </Button>
          <Button type="submit">Apply</Button>
        </div>
      </form>
      <ul className="flex flex-col gap-2 text-sm">
        {shown.map((paper) => (
          <li key={paper.title} className="flex justify-between gap-3">
            <span className="min-w-0 wrap-break-word">{paper.title}</span>
            <span className="shrink-0 text-muted-foreground tabular-nums">{paper.year}</span>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

Example: A press that goes to another page is an anchor drawn through `buttonVariants` (`docs/system/examples/button/as-link.tsx`)

```tsx
import { buttonVariants } from "@/components/cobalt/ui/button";
import { Item, ItemActions, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/cobalt/ui/item";

// With a router, put the same classes on its Link: <Link to="/rooms/harbour/book" className={buttonVariants()}>.
export default function Example() {
  return (
    <ItemGroup variant="card" className="w-full max-w-sm">
      <Item>
        <ItemContent>
          <ItemTitle>Harbour room</ItemTitle>
          <ItemDescription>Seats 12, free from 2pm</ItemDescription>
        </ItemContent>
        <ItemActions>
          <a href="#book-harbour-room" className={buttonVariants()}>
            Book room
          </a>
        </ItemActions>
      </Item>
    </ItemGroup>
  );
}
```

## Variants

### variant
- `default`: the view's one primary action, the accent fill. Used at 1 call site, the alert dialog's action.
- `secondary`: every other action, the grey fill. Used at 2 call sites, the empty state's next step and the alert dialog's cancel.
- `ghost`: an action inside a row, a bar or a corner, no fill at rest. Used at 3 call sites, the two close buttons and the icon button.
- `destructive`: an action that removes something, red text on a light red background. Used at 0 call sites in the registry; the alert dialog's action takes it from the caller.

A link that sits in text or beside a heading, such as "See all", is a `TextLink`. A bordered button has no variant; use `secondary`.

Example: The one primary action of a view, in the accent (`docs/system/examples/button/variant-default.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";

const steps = ["Details", "Guests", "Review"];

// Moving between steps happens on the page, so the answer is instant and needs no spinner.
export default function Example() {
  const [step, setStep] = useState(0);
  const last = step === steps.length - 1;
  return (
    <div className="flex w-full max-w-xs items-center justify-between gap-4">
      <span className="text-sm text-muted-foreground tabular-nums">
        Step {step + 1} of {steps.length}: {steps[step]}
      </span>
      <Button onClick={() => setStep(last ? 0 : step + 1)}>{last ? "Start over" : "Continue"}</Button>
    </div>
  );
}
```

Example: The grey fill, for every action but the primary one (`docs/system/examples/button/variant-secondary.tsx`)

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

import { PlusIcon } from "@/components/cobalt/icon";
import { Button } from "@/components/cobalt/ui/button";

const people = ["Sofia Reyes", "Jonas Berg", "Mira Okafor", "Theo Lind"];

// Adding a row to a list you are still editing happens on the page, so it is instant. The button
// sits above the list, so the list grows down from it and the button never moves under the pointer.
export default function Example() {
  const [count, setCount] = useState(1);
  return (
    <div className="flex w-full max-w-xs flex-col gap-3">
      <Button
        variant="secondary"
        className="self-start"
        disabled={count === people.length}
        onClick={() => setCount(count + 1)}
      >
        <PlusIcon data-icon="inline-start" />
        Add guest
      </Button>
      <ul aria-label="Guests" className="flex flex-col gap-1 text-sm">
        {people.slice(0, count).map((name) => (
          <li key={name}>{name}</li>
        ))}
      </ul>
    </div>
  );
}
```

Example: No fill at rest, for an action repeated on every row (`docs/system/examples/button/variant-ghost.tsx`)

```tsx
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
import { useState } from "react";

import { Button } from "@/components/cobalt/ui/button";
import { curves, times } from "@/lib/cobalt/motion";

// The list is a draft until the invitations are sent, so removing a name answers at once. The row
// leaves: it fades while its height closes, so the rows below slide up instead of jumping. With
// reduced motion it only fades.
export default function Example() {
  const [guests, setGuests] = useState(["Ana Lima", "Kenji Sato", "Maya Patel"]);
  const reduced = useReducedMotion() === true;
  return (
    <ul className="flex w-full max-w-xs flex-col text-sm">
      <AnimatePresence initial={false}>
        {guests.map((guest) => (
          <motion.li
            key={guest}
            exit={reduced ? { opacity: 0 } : { opacity: 0, height: 0 }}
            transition={{ duration: times.leave, ease: curves.out }}
            className="overflow-hidden"
          >
            <div className="flex items-center justify-between gap-3 py-0.5">
              <span className="min-w-0 truncate">{guest}</span>
              <Button
                variant="ghost"
                size="sm"
                aria-label={`Remove ${guest}`}
                onClick={(event) => {
                  // Focus moves to the next row's Remove, so the keyboard keeps its place.
                  const row = event.currentTarget.closest("li");
                  const next = row?.nextElementSibling ?? row?.previousElementSibling;
                  next?.querySelector("button")?.focus();
                  setGuests((was) => was.filter((name) => name !== guest));
                }}
              >
                Remove
              </Button>
            </div>
          </motion.li>
        ))}
      </AnimatePresence>
      {guests.length === 0 && <li className="text-muted-foreground">No guests on the list.</li>}
    </ul>
  );
}
```

Example: Red text on a light red background, and a confirmation first (`docs/system/examples/button/variant-destructive.tsx`)

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

import {
  AlertDialog,
  AlertDialogCancel,
  AlertDialogContent,
  AlertDialogDescription,
  AlertDialogError,
  AlertDialogFooter,
  AlertDialogHeader,
  AlertDialogTitle,
  AlertDialogTrigger,
} from "@/components/cobalt/ui/alert-dialog";
import { Button } from "@/components/cobalt/ui/button";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

export default function Example() {
  const [open, setOpen] = useState(false);
  const remove = useAction(async () => {
    await request();
    setOpen(false);
    toast("Autumn reading night deleted", { description: "Its 14 guests were emailed." });
  });
  return (
    <>
      <AlertDialog
        open={open}
        onOpenChange={(next) => {
          setOpen(next);
          if (!next) remove.reset();
        }}
      >
        <AlertDialogTrigger render={<Button variant="destructive" />}>Delete event</AlertDialogTrigger>
        <AlertDialogContent status={remove.status}>
          <AlertDialogHeader>
            <AlertDialogTitle>Delete Autumn reading night?</AlertDialogTitle>
            <AlertDialogDescription>
              Its 14 bookings are cancelled and their guests are told.
            </AlertDialogDescription>
          </AlertDialogHeader>
          <AlertDialogFooter>
            {remove.error !== null && (
              <AlertDialogError>The event was not deleted. Try again.</AlertDialogError>
            )}
            <AlertDialogCancel>Keep event</AlertDialogCancel>
            <StateButton
              variant="destructive"
              status={remove.status}
              pendingLabel="Deleting"
              successLabel="Deleted"
              failureLabel="Not deleted"
              onClick={() => void remove.run()}
            >
              Delete event
            </StateButton>
          </AlertDialogFooter>
        </AlertDialogContent>
      </AlertDialog>
    </>
  );
}
```

### size
- `default`: `--control` tall (36px), `text-sm`, with `touch-target`, so a coarse pointer reaches 44px (measured 36px tall before, 44px after, iPhone 13 emulation, 2026-10-17). Used at 5 call sites.
- `sm`: `--control-sm` tall (32px), with `touch-target`, so under a coarse pointer the hit area reaches `--touch` (44px) while the drawn box stays 32px. Used at 0 call sites in the registry.
- `lg`: `--control-lg` tall (40px). Used at 0 call sites.
- `icon`, `icon-sm`, `icon-lg`: a square at the matching height for an icon-only button, with a 16px glyph; `icon` and `icon-sm` carry `touch-target` like `sm`, and `IconButton` adds it to every size. Used at 3 call sites, the two close buttons (`icon-sm`) and the icon button (`icon`).
- `icon-xs`: a 28px square with a 6px corner (`rounded-sm`), for a button inset 4px inside a 36px box such as a field or a code chip, where the box's 10px corner less the inset makes the two concentric (D38); it carries `touch-target`. Used at 0 call sites in the registry; the copy button's chip and command examples pass it.

Example: 36px, the height every control in a row shares (`docs/system/examples/button/size-default.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";

// The room's listing is a draft until it is published, so adding a feature answers at once.
export default function Example() {
  const [features, setFeatures] = useState(["Projector", "Whiteboard"]);
  const [draft, setDraft] = useState("");
  const feature = draft.trim();
  return (
    <form
      className="flex w-full max-w-sm flex-col gap-3"
      onSubmit={(event) => {
        event.preventDefault();
        if (feature === "" || features.includes(feature)) return;
        setFeatures([...features, feature]);
        setDraft("");
      }}
    >
      <div className="flex items-center gap-2">
        <Input
          aria-label="Room feature"
          placeholder="Step-free access"
          value={draft}
          onChange={(event) => setDraft(event.target.value)}
        />
        <Button type="submit" variant="secondary" disabled={feature === ""}>
          Add
        </Button>
      </div>
      <p className="text-sm text-muted-foreground">{features.join(", ")}</p>
    </form>
  );
}
```

Example: 32px, for a button beside a field or in a header (`docs/system/examples/button/size-sm.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";

// Clearing filters happens on the page, so the list answers at once. The buttons sit at the row's
// end and Undo keeps its room while hidden, so nothing moves when the count changes.
export default function Example() {
  const [filters, setFilters] = useState(3);
  return (
    <div className="flex w-full max-w-xs items-center justify-between gap-3">
      <span className="text-sm text-muted-foreground tabular-nums">
        {filters === 0 ? "No filters" : `${filters} filters`}
      </span>
      <div className="flex items-center gap-1">
        <Button
          variant="ghost"
          size="sm"
          className={filters === 0 ? undefined : "invisible"}
          onClick={() => setFilters(3)}
        >
          Undo
        </Button>
        <Button variant="secondary" size="sm" disabled={filters === 0} onClick={() => setFilters(0)}>
          Clear filters
        </Button>
      </div>
    </div>
  );
}
```

Example: 40px, for the last action of a phone flow (`docs/system/examples/button/size-lg.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import { StateButton } from "@/components/cobalt/ui/state-button";
import { useAction } from "@/lib/cobalt/use-action";

// Stands in for your API call. It answers after 900ms, and fails while the browser is offline or the
// address has ?network=offline.
const request = () =>
  new Promise<void>((resolve, reject) =>
    setTimeout(() => {
      const offline = !navigator.onLine || new URLSearchParams(location.search).get("network") === "offline";
      if (offline) reject(new Error("offline"));
      else resolve();
    }, 900),
  );

export default function Example() {
  const send = useAction(request);
  // Skipping only changes this screen, so it answers at once.
  const [skipped, setSkipped] = useState(false);
  if (skipped)
    return (
      <div className="flex w-full max-w-xs flex-col gap-2">
        <p className="text-sm text-muted-foreground">
          No invitation sent. You can send one from the event page.
        </p>
        <Button size="lg" variant="secondary" onClick={() => setSkipped(false)}>
          Invite Mira Okafor
        </Button>
      </div>
    );
  return (
    <div className="flex w-full max-w-xs flex-col gap-2">
      <StateButton
        size="lg"
        status={send.status}
        onClick={() => void send.run()}
        pendingLabel="Sending"
        successLabel="Sent"
        failureLabel="Not sent"
      >
        Invite Mira Okafor
      </StateButton>
      <Button size="lg" variant="ghost" disabled={send.status === "pending"} onClick={() => setSkipped(true)}>
        Not now
      </Button>
      <p role="status" className="text-sm text-destructive">
        {send.error !== null ? "The invitation was not sent. Check your connection and try again." : ""}
      </p>
    </div>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| default | render | press, focus | the label | screenshot |
| hover | pointer over, under `(hover: hover)` | press | the fill one step darker; no shape change | by hand |
| focus-visible | keyboard focus | press with Enter or Space | the 2px ring, 2px outside the corner | 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 |
| disabled | `disabled` | nothing; focus skips it unless `focusableWhenDisabled` | half opacity; 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 or popover trigger | close the menu | the fill stays as on hover while open | screenshot |
| pending | the host wraps the button in `StateButton` with `status="pending"` | nothing; a second press returns early | the spinner inside the box, the box and the name unchanged | test |

Example: Disabled until the field is filled, with the reason beside it (`docs/system/examples/button/state-disabled.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import { Input } from "@/components/cobalt/ui/input";

// Adding a guest to a list you are still editing stays on the page, so it answers at once.
export default function Example() {
  const [name, setName] = useState("");
  const [guests, setGuests] = useState(["Mira Okafor", "Jonas Berg"]);
  const ready = name.trim().length > 0;
  return (
    <form
      className="flex w-full max-w-sm flex-col gap-2"
      onSubmit={(event) => {
        event.preventDefault();
        if (!ready) return;
        setGuests((was) => [...was, name.trim()]);
        setName("");
      }}
    >
      <div className="flex items-center gap-2">
        <Input
          aria-label="Guest name"
          placeholder="Guest name"
          value={name}
          onChange={(event) => setName(event.target.value)}
        />
        <Button type="submit" variant="secondary" disabled={!ready} aria-describedby="add-reason">
          Add guest
        </Button>
      </div>
      <p id="add-reason" className="text-xs text-muted-foreground">
        {ready ? "Ready to add." : "Type a name to add a guest."}
      </p>
      <ul aria-live="polite" className="flex flex-col gap-1 text-sm">
        {guests.map((guest, index) => (
          <li key={index}>{guest}</li>
        ))}
      </ul>
    </form>
  );
}
```

Example: The fill stays while the button's menu is open (`docs/system/examples/button/state-expanded.tsx`)

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

import { Button } from "@/components/cobalt/ui/button";
import {
  DropdownMenu,
  DropdownMenuCheckboxItem,
  DropdownMenuContent,
  DropdownMenuTrigger,
} from "@/components/cobalt/ui/dropdown-menu";
import { date } from "@/lib/cobalt/format";
import { cn } from "@/lib/cobalt/utils";

const events = [
  { title: "Autumn reading night", date: "2026-10-23", free: true, online: false },
  { title: "Motion study group", date: "2026-10-29", free: true, online: true },
  { title: "Tokens workshop", date: "2026-11-04", free: false, online: true },
  { title: "Archive tour", date: "2026-11-12", free: false, online: false },
];

// Filtering rows already on the page answers at once.
export default function Example() {
  const [free, setFree] = useState(false);
  const [online, setOnline] = useState(false);
  const shown = events.filter((event) => (!free || event.free) && (!online || event.online));
  return (
    <div className="flex w-full max-w-xs flex-col gap-3">
      <DropdownMenu>
        <DropdownMenuTrigger render={<Button variant="secondary" className="self-start" />}>
          Filters
        </DropdownMenuTrigger>
        <DropdownMenuContent>
          <DropdownMenuCheckboxItem checked={free} onCheckedChange={setFree}>
            Free
          </DropdownMenuCheckboxItem>
          <DropdownMenuCheckboxItem checked={online} onCheckedChange={setOnline}>
            Online
          </DropdownMenuCheckboxItem>
        </DropdownMenuContent>
      </DropdownMenu>
      {/* Every event sits invisible in the same cell, so the list keeps its tallest height. */}
      <div className="grid">
        {[events, shown].map((rows, layer) => (
          <ul
            key={layer}
            aria-hidden={layer === 0 || undefined}
            className={cn("col-start-1 row-start-1 flex flex-col gap-1 text-sm", layer === 0 && "invisible")}
          >
            {rows.map((event) => (
              <li key={event.title} className="flex justify-between gap-3">
                <span className="min-w-0 truncate">{event.title}</span>
                <span className="shrink-0 text-muted-foreground tabular-nums">{date(event.date)}</span>
              </li>
            ))}
            {layer === 1 && rows.length === 0 && (
              <li className="text-muted-foreground">No events match these filters.</li>
            )}
          </ul>
        ))}
      </div>
    </div>
  );
}
```

### State precedence
- Disabled and hover: disabled wins. The `hover` variant never matches a disabled element (`registry/cobalt/styles.css`), so no hover fill shows; the button still takes the pointer, so a double-click on it never reaches the words behind it.
- Disabled and focus-visible: disabled wins. The button leaves the tab order unless `focusableWhenDisabled` is set, and then the ring shows on the faded button.
- Hover and focus-visible: both show. The ring is an outline and the fill is a background, so neither hides the other.
- Pressed and hover: both show. The tint sits over the hover fill.
- Expanded and hover: expanded wins. The fill is already the hover fill, so hovering changes nothing.
- Pending and every other state: pending wins, in `StateButton`, which sets `aria-disabled` and `aria-busy` and keeps focus.

### Motion
| Trigger | Kind | Preset | Properties | Reduced motion |
|---|---|---|---|---|
| pointer-down to pointer-up | input | `pressable`, `--t-press` on `--curve` | box-shadow, color, background-color | `box-shadow` is not in the reduced-motion list, so the press tint is instant; the colour change stays |
| pointer over and out | announce | `--t-press` on `--curve` | background-color, color | the same colour change |

## Props

<!-- Props generated from registry/cobalt/ui/button.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `size?` | `"default" \| "sm" \| "lg" \| "icon" \| "icon-sm" \| "icon-xs" \| "icon-lg"` | `"default"` | `default` `--control` tall (36px); `sm` `--control-sm` tall (32px); `lg` `--control-lg` tall (40px); `icon`, `icon-sm`, `icon-lg` a square at the matching height for an icon-only button; `icon-xs` a 28px square with a 6px corner (`rounded-sm`). |
| `variant?` | `"default" \| "secondary" \| "ghost" \| "destructive"` | `"default"` | `default` the view's one primary action; `secondary` every other action; `ghost` an action inside a row; `destructive` an action that removes something. |

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

Every native button attribute passes through: `type` (defaults to `button` through the primitive, so a button in a form never submits by accident), `disabled`, `form`, `name`, `aria-*`. `ref` reaches the `<button>`. `render` swaps the element for another part's own, such as a dialog's close. An anchor or a router's Link passed to `render` (an element with `href` or `to`) stays a link: Button draws it through `useRender` instead of Base UI's Button, so it gets no `role="button"` and is read and opened as a link; `disabled` turns it into a `span` with `role="link"` and `aria-disabled="true"` and no address. `className` is merged last and is for placement.

## Usage

### When to use
- You start an action now: save, publish, invite, delete, open a menu.
- The view needs one primary action, and every other action beside it.

### When not to use
- The control is on or off, such as a filter. Use Pill instead.
- The control stays pressed, such as bold in a toolbar. Use Toggle instead.
- The action is slow and the button must report it. Use StateButton instead.
- The press navigates to a page. Pass the link to `render` instead, so it stays a link. Use BackLink for the way back, and TextLink for a link in text.
- The button is only an icon. Use IconButton instead, which names it once for the tooltip and the screen reader.

### Rules
- `rule/button-one-primary`: When a view holds more than one action, give the `default` variant to exactly 1 of them and `variant="secondary"` or `variant="ghost"` to the rest, because the accent fill is how the user finds the next step, and two of them leave no next step. Evidence: person D13; app 1/7 call sites in the registry use the default fill, the alert dialog's action (`rg -n "<Button\b" registry/cobalt`). Check: review of every view in the showcase.
  - Don't: `<Button>Save</Button> <Button>Publish</Button>`
  - Do: `<Button variant="secondary">Save</Button> <Button>Publish</Button>`
- `rule/button-render-for-links`: When a button navigates, pass the link, or the host's router link, to `render`, or put `buttonVariants()` on it, instead of wrapping a `Button` in a link or a link in a `Button`, because two elements give two tab stops and two roles for one action. Evidence: principle platform: one interactive element per action, a nested interactive is invalid HTML; single use registry/cobalt/ui/back-link.tsx:28, BackLink puts `buttonVariants()` on its link; measured `<Button render={<a href="/events" />}>` renders `<a href="/events">` with no `role` (react-dom/server, 2026-10-17, `button.test.tsx`). Check: lint trap/link-wraps-button and trap/link-as-button (scripts/check-system.mjs); test `button.test.tsx` renders an anchor and a router Link through `render` and finds no `role`.
  - Don't: `<a href="/events"><Button>Events</Button></a>`
  - Do: `<Button variant="secondary" render={<a href="/events" />}>Events</Button>`
- `rule/button-name-the-icon`: When a button has only an icon, give it an `aria-label` or render it through `IconButton`, because a screen reader announces an unnamed button as "button" and nothing else. Evidence: principle wcag: 4.1.2 Name, role, value, every control needs an accessible name; app 3/3 icon-only call sites carry a name (`registry/cobalt/ui/sheet.tsx:601`, `registry/cobalt/ui/dialog.tsx:118`, `registry/cobalt/ui/icon-button.tsx:53`). Check: test `button.test.tsx` renders an unnamed icon button and expects the development warning; lint trap/button-icon-name.
  - Don't: `<Button size="icon"><XIcon /></Button>`
  - Do: `<IconButton icon={<XIcon />} label="Close" />`
- `rule/button-no-layout-override`: When a button needs a different fill, height or corner, add a variant or size instead of passing them through `className`, and keep `className` for placement such as `w-full` or a margin, because a one-off class skips the hover, pressed and disabled states the variant carries. Evidence: principle heuristic: consistency and standards, one component carries every state; app 2/7 call sites pass `className`, both for placement (`registry/cobalt/ui/dialog.tsx:112`, `registry/cobalt/ui/sheet.tsx:595`). Check: lint rule/component-override (scripts/check-system.mjs).
  - Don't: `<Button className="h-12 rounded-none bg-good">Approve</Button>`
  - Do: `<Button size="lg" className="w-full">Approve</Button>`
- `rule/button-keeps-its-box-when-busy`: When an action takes longer than a press, wrap the button in `StateButton` with `status="pending"` instead of swapping its label for "Saving" or a spinner, because a label swap changes the box and the accessible name mid-action, and a bare `disabled` drops keyboard focus to the page. Evidence: person D2; principle wcag: 4.1.3 Status messages, the state is announced beside the control, not by renaming it. Check: lint trap/loading-label-swap (scripts/check-system.mjs); test on StateButton.
  - Don't: `<Button disabled={saving}>{saving ? "Saving" : "Save"}</Button>`
  - Do: `<StateButton status={saving ? "pending" : "idle"} pendingLabel="Saving">Save</StateButton>`
- `rule/button-server-action-reports`: When a button's action reaches a server, run it through `useAction` and show its `status` on a `StateButton`, and when the action stays on the page, answer at once, because a label that flips to "Saved" before the request ends claims a success that may not happen and hides the failure. Evidence: person D39; principle heuristic: visibility of system status, the button says what the request is doing. Check: review of every `onClick` that sets a done label without awaiting a request.
  - Don't: `<Button onClick={() => setLabel("Saved")}>Save changes</Button>`
  - Do: `<StateButton status={save.status} onClick={() => void save.run()}>Save changes</StateButton>`
- `rule/button-disabled-says-why`: When a button is `disabled` because the form is not ready, put the reason in text beside it and point `aria-describedby` at it, because a greyed button with no reason leaves you guessing what to fix. Evidence: person D39; principle heuristic: help users recognize, diagnose and recover, the missing step is named. Check: review of every `disabled` that depends on form state.
  - Don't: `<Button disabled={!title}>Publish</Button>`
  - Do: `<Button disabled={!title} aria-describedby="publish-reason">Publish</Button> <p id="publish-reason">Add a title to publish.</p>`
- `rule/button-small-keeps-the-touch-target`: When a button is drawn shorter than 36px, use `size="sm"` or `size="icon-sm"`, or `IconButton`, instead of a default button shrunk with a `className` such as `h-8` or `size-8`, because the small sizes carry `touch-target`, which extends the hit area to 44px under a coarse pointer without moving anything, and a class that only shrinks the box leaves a 32px target on a phone. Evidence: measured `sm` and `icon-sm` drawn at 32px with a 44px `::after` hit area, a tap 4px above the box still landing on the button, at 390 with a touch pointer (.design-system/tmp/fp-core/touch.mjs); principle platform: Apple's 44pt minimum touch target; principle wcag: 2.5.8 Target size (minimum). Check: test `button.test.tsx`, the small sizes carry the touch target; review of every `className` that sets a height on a Button.
  - Don't: `<Button variant="ghost" className="h-8 px-2">More</Button>`
  - Do: `<Button variant="ghost" size="sm">More</Button>`

### Content
- Follows `rule/writing-button-verb`.
- `rule/button-label-is-the-outcome`: When the label names the action, write the verb and its object, such as "Create event", instead of a bare "OK", "Yes" or "Submit", because the label is read once and trusted to say what happens. Evidence: person D11; principle heuristic: match between system and the real world, the label names the outcome. Check: lint copy/template on the button slot (scripts/copy-check.mjs).
  - Don't: `<Button>OK</Button>`
  - Do: `<Button>Create event</Button>`

### Anti-slop
- `rule/button-no-icon-by-default`: When a button has a text label, leave the icon off unless the icon is how the user finds the action by shape, such as a plus on "New item", because an icon beside every label makes none of them findable. Evidence: principle heuristic: aesthetic and minimalist design, every extra glyph dilutes the one that matters; app 0/7 registry call sites pair an icon with a label. Check: review.
  - Don't: `<Button><PencilIcon /> Edit</Button> <Button><TrashIcon /> Delete</Button>`
  - Do: `<Button>Edit</Button> <Button variant="destructive">Delete</Button>`
- `rule/button-no-red-fill`: When an action removes something, use `variant="destructive"`, which is red text on a wash, instead of a red fill, because a red fill shouts on every screen and the word already says what will happen. Evidence: person D26; app 0/7 call sites paint a red fill. Check: lint rule/component-override on Button (scripts/check-system.mjs); review.
  - Don't: `<Button className="bg-bad text-white">Delete</Button>`
  - Do: `<Button variant="destructive">Delete event</Button>`

### Limits
- `rule/button-label-length`: When a label would run past 49 characters at 390px, shorten it or give the button `className="w-full"` with a label that fits, because past that width the label wraps to a second line inside the box, which keeps it on screen, with a one-line label's room above and below it, but makes the button 46px beside 36px controls. Evidence: measured overflow at 50 characters in a 310px column at 390px before labels could wrap, .design-system/evidence/button/grow-text-390.json; measured the German "Benachrichtigungseinstellungen speichern" wrapping to two lines inside a 272px column at 320px, `docs/research/2026-10-16-break-ui-inputs.md`. Check: probe trap/button-label-wrap on the showcase at 390; the stress page `/stress/button` at 320.
  - Don't: `<Button>Create an event for the whole team and invite everyone who signed up</Button>`
  - Do: `<Button>Create event</Button>`

## Accessibility
Rests on `<button>` from Base UI `Button`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the button | focuses it and shows the ring | the button | by hand |
| Enter or Space | the button | presses it | the button, unless the action moves focus | by hand |
| Enter or Space | a disabled button with `focusableWhenDisabled` | nothing | the button | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | button | its text, or `aria-label` on an icon-only button | `disabled`, `aria-expanded` from a trigger, `aria-busy` and `aria-disabled` from StateButton | the name and role on focus; "expanded" or "collapsed" on a trigger | a11y scan |

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--control-sm`, `--control`, `--control-lg`, `--r-lg`, `--t-press`, `--curve`, `--ring` |
| default | rest | `--primary`, `--primary-foreground` |
| default | hover | `--primary-hover` |
| secondary | rest | `--secondary`, `--secondary-foreground` |
| secondary | hover | `--muted-hover` |
| ghost | hover | `--muted`, `--foreground` |
| destructive | rest | `--destructive` at 10 percent, `--destructive` |

## Related
- Pill: a control that is on or off.
- Toggle: a button that stays pressed.
- StateButton: a button that reports a slow action in place.
- IconButton: a button with only an icon, named once.
- BackLink: the way back to a list.
- TextLink: a link inside text or beside a heading.
- Avatar: shows who someone is.
- Badge: marks a thing with one word or a count that you read and do not press.
- ContextMenu: offers the commands for an area from a right click, a long press or Shift+F10 on it.
- DropdownMenu: offers the commands for one thing from a trigger, one of them chosen and the menu gone.
- Field: holds one labelled control with its description and its error.
- Tabs: switches between views of one thing in place.
- Tag: names a category or a topic in a colour that follows the name.
- CopyButton: copies one text and confirms it in place.
- Kbd: shows the key that presses a button.
- SaveToggle: a save that moves at once and moves back if refused.
- FileDrop: takes files by drop or by a button, and shows each one's upload as it goes.
- Collapsible: a row that opens to its details.
- Grow: a button that turns into a small form.
- SaveLine: a quiet line saying a form's changes are saving, saved or not saved.
