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

## Description
A button that stays on or off, such as a filter over a list or a tool in a toolbar.

`import { Toggle, toggleVariants } from "@/components/cobalt/ui/toggle"`, source `registry/cobalt/ui/toggle.tsx`, status `ready-with-gaps`.
`import { Pill, pillClasses, pillLabel } from "@/components/cobalt/ui/pill"`, source `registry/cobalt/ui/pill.tsx`, status `ready-with-gaps`.
Foundation: `shadcn toggle (base-luma, base)` for Toggle and `Base UI Toggle` for Pill. 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/weight-shift`, `trap/focus-ring-shape`, `trap/hover-beats-focus`, `trap/disabled-still-hovers`, `trap/press-delayed`, `trap/touch-tap-highlight`, `trap/color-only-status`, `trap/toggle-switch-submit`, `trap/toggle-indeterminate`, `trap/button-label-wrap`, `trap/tooltip-essential`, `trap/open-trigger-unfocused`, `trap/reduced-motion-ignored`, `trap/motion-layout-property`, `trap/motion-transition-all`, `trap/motion-restart`, `trap/motion-overshoot`, `trap/motion-linear`.

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| shadcn `toggle` on Base UI `Toggle`: a native `<button type="button">`, `pressed`, `defaultPressed` and `onPressedChange`, `aria-pressed`, `disabled`, `render`, Space and Enter, the `size` axis, a 16px glyph for any `svg` without a `size-*` class | `pressable`, the `--hover` press tint on the press duration; heights from `--control-sm`, `--control` and `--control-lg` as `min-h` with a matching `min-w`, so text zoom grows the box; the control corner, `--r-control`; 12px of side padding (16px at `lg`) and a 6px gap to a glyph, Button's; the `icon`, `icon-sm` and `icon-lg` sizes for a glyph alone, square as IconButton is, with `touch-target` on `icon-sm` so a phone still gets a 44px tap; no fill at rest and `--muted` under the pointer; the pressed look as the ink fill with light text, kept under the pointer at 85 percent so the state still shows; the shadcn `outline` variant dropped; no shadow; `max-w-full`, and a text label wrapped in a span cut with an ellipsis, given `dir="auto"`, and shown whole in the system tooltip while it is cut (`TruncatedText`); `select-none`, so a double-click selects nothing and a label on the ink fill is never selected unreadably; the trim beside a glyph on the logical side (`ps`, `pe`) |
| Base UI `Toggle`, the same primitive | `pillClasses(on)`: the control corner (`--r-control`) at `--control` (36px), Button's 12px of side padding, 6px gap and trim to 10px beside a `data-icon` glyph, so a pill and a button of one height line up, with a 20px line box so descenders are not clipped when a label truncates, `max-w-full` so a pill is never wider than its row, and `pillLabel`, which wraps a text label in a span cut with an ellipsis, given `dir="auto"`, and shows it whole in the system tooltip while it is cut (`TruncatedText`); `select-none`, since selected text on the ink fill measured 1.19:1; the grey fill at rest and the ink fill with light text when pressed, kept under the pointer; its own `useState` mirror so the look follows the primitive's state whether controlled or not; `aria-expanded` styles for a pill that opens a popover; `data-slot="pill"`; `pillClasses` exported for the links and triggers that wear the look, such as ChipRow and FilterBar; `touch-target`, so under a coarse pointer the hit area reaches `--touch` (44px) without changing the drawn size, measured 44px tall over a 36px pill at 390 with a touch pointer (.design-system/tmp/fp-core/touch.mjs). The fill alone shows the state, so off and pressed have the same content and the same width |

## Examples
Tools in a toolbar, each named by its tooltip, filters over a list, and a filter that opens a popover.

Real uses, 0 call sites (`rg -n "<Toggle\b" app registry --glob '!registry/cobalt/ui/*'`): the showcase chrome renders none, the registry's own ui folder never counts, and the examples folder does not count. Pill has 0 call sites too (`rg -n "<Pill\b" app registry --glob '!registry/cobalt/ui/*'`).

Uses inside the registry, which the rules below sweep as the system's own call sites:
- `pillClasses(active)` on ChipRow's links at the chip height, the current one pressed, `registry/cobalt/ui/chip-row.tsx:193`.
- `pillClasses` on FilterBar's popover triggers at the chip height, filled once a filter applies, `registry/cobalt/ui/filter-bar.tsx:256`, and on its sheet trigger, `registry/cobalt/ui/filter-bar.tsx:511`.
- The segmented control and the tabs draw their own indicator and are not toggles.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/toggle/default.tsx` | default | Tools above a list of filings, each a toggle that adds one detail to every row |
| `docs/system/examples/toggle/look-pill.tsx` | look=pill | Kinds of item that narrow a reading list, any number on at once |
| `docs/system/examples/toggle/look-plain.tsx` | look=plain | Two tools over a note, each pressed for as long as it applies |
| Not applicable: the default size is every toggle in look-plain.tsx | size=default | 36px, the height of a button |
| `docs/system/examples/toggle/size-sm.tsx` | size=sm | Beside a list's heading, it adds the archived lists to the rows |
| Not applicable: lg sits beside a large Button or search field, and no example here has one | size=lg | 40px, the large control height |
| Not applicable: the icon size is every toggle in default.tsx | size=icon | A 36px square around a glyph |
| `docs/system/examples/toggle/size-icon-sm.tsx` | size=icon-sm | Tools in a dense header, each named by its tooltip, that add details to the rows |
| Not applicable: icon-lg sits beside a large Button, and no example here has one | size=icon-lg | A 40px square around a glyph |
| Not applicable: off is every toggle at rest in default.tsx but the first | state:off | No fill on a toggle, the grey fill on a pill |
| `docs/system/examples/toggle/state-pressed.tsx` | state:pressed | Both looks pressed, in the ink fill with light text at the same width as off |
| Not applicable: hover is reached with the pointer on any example | state:hover | The grey fill, a step darker on a pill, or the ink at 85 percent when pressed |
| Not applicable: focus-visible is reached with the keyboard on any example | state:focus-visible | The 2px ring outside the corner |
| Not applicable: active is the `--hover` tint while the pointer is down on any example | state:active | The press tint over the fill |
| `docs/system/examples/toggle/state-disabled.tsx` | state:disabled | Both looks, off and pressed, at half opacity; a press or a double-click does nothing |
| `docs/system/examples/toggle/expanded.tsx` | state:expanded | The grey fill deepens while its popover is open, and turns to ink once a range applies |
| `docs/system/examples/toggle/size-icon-sm.tsx` | composition:Tooltip | Each tooltip repeats its toggle's aria-label, and nothing more |
| Not applicable: the tiles show each look and each size | matrix:look,size | Both looks at every size |

Example: Tools above a list of filings, each a toggle that adds one detail to every row (`docs/system/examples/toggle/default.tsx`)

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

import { Toggle } from "@/components/cobalt/ui/toggle";

const filings = [
  { fund: "Northgate Credit", form: "13F", filed: "Oct 14", manager: "Ana Lima" },
  { fund: "Harbor Lane Partners", form: "N-PORT", filed: "Oct 9", manager: "Kenji Sato" },
  { fund: "Elm Street Value", form: "13F", filed: "Sep 30", manager: "Maya Patel" },
  { fund: "Westbrook Income", form: "N-PORT", filed: "Sep 26", manager: "Lars Berg" },
];

export default function Example() {
  // Each one shows more of the rows already loaded, so it answers at once. Every detail has its own
  // slot on the second line, so turning one on moves none of the others.
  const [dates, setDates] = useState(true);
  const [forms, setForms] = useState(false);
  const [managers, setManagers] = useState(false);
  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <div role="group" aria-label="Show on each filing" className="flex flex-wrap items-center gap-1">
        <Toggle size="sm" pressed={dates} onPressedChange={setDates}>
          Dates
        </Toggle>
        <Toggle size="sm" pressed={forms} onPressedChange={setForms}>
          Forms
        </Toggle>
        <Toggle size="sm" pressed={managers} onPressedChange={setManagers}>
          Managers
        </Toggle>
      </div>
      <ul className="flex flex-col gap-2 text-sm">
        {filings.map((filing) => (
          <li key={filing.fund} className="flex flex-col">
            <span className="font-medium">{filing.fund}</span>
            <span className="grid min-h-lh grid-cols-3 gap-2 text-muted-foreground tabular-nums">
              <span>{dates && filing.filed}</span>
              <span>{forms && filing.form}</span>
              <span className="min-w-0 truncate">{managers && filing.manager}</span>
            </span>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

Example: Each tooltip repeats its toggle's aria-label, and nothing more (`docs/system/examples/toggle/size-icon-sm.tsx`)

```tsx
import { useState, type ReactNode } from "react";

import { ClockIcon, MapPinIcon } from "@/components/cobalt/icon";
import { Toggle } from "@/components/cobalt/ui/toggle";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/cobalt/ui/tooltip";

const events = [
  { name: "Fund managers forum", time: "09:30", place: "Lisbon" },
  { name: "Credit outlook briefing", time: "13:00", place: "Online" },
  { name: "Quarterly review", time: "16:00", place: "Oslo" },
];

// The name is the toggle's aria-label and the tooltip's text, so it is written once.
function Tool({
  name,
  pressed,
  onPressedChange,
  children,
}: {
  name: string;
  pressed: boolean;
  onPressedChange: (pressed: boolean) => void;
  children: ReactNode;
}) {
  return (
    <Tooltip>
      <TooltipTrigger
        render={<Toggle size="icon-sm" aria-label={name} pressed={pressed} onPressedChange={onPressedChange} />}
      >
        {children}
      </TooltipTrigger>
      <TooltipContent>{name}</TooltipContent>
    </Tooltip>
  );
}

export default function Example() {
  // Details of the rows already loaded, so each answers at once.
  const [times, setTimes] = useState(true);
  const [places, setPlaces] = useState(false);
  return (
    <div className="flex w-full max-w-sm flex-col gap-2">
      <div className="flex items-center justify-between gap-3">
        <h3 className="text-sm font-medium">This week</h3>
        <div className="flex items-center gap-1">
          <Tool name="Show times" pressed={times} onPressedChange={setTimes}>
            <ClockIcon />
          </Tool>
          <Tool name="Show places" pressed={places} onPressedChange={setPlaces}>
            <MapPinIcon />
          </Tool>
        </div>
      </div>
      <ul className="flex flex-col gap-1 text-sm">
        {events.map((event) => (
          <li key={event.name} className="flex justify-between gap-3">
            <span className="min-w-0 wrap-break-word">{event.name}</span>
            <span className="shrink-0 text-muted-foreground tabular-nums">
              {[times && event.time, places && event.place].filter(Boolean).join(", ")}
            </span>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

## Variants
Both looks press to the same ink fill with light text and keep their width; they differ at rest. Neither has a `variant` prop.

### look
Not a prop: the look is the part you import, `Pill` or `Toggle`.
- `pill`: `Pill`, the grey fill at rest, for a filter over a list among other filters, any number on. Used at 0 call sites; ChipRow and FilterBar wear it through `pillClasses`.
- `plain`: `Toggle`, no fill at rest, for a tool in a toolbar that stays pressed while it applies. Used at 0 call sites.

Example: Kinds of item that narrow a reading list, any number on at once (`docs/system/examples/toggle/look-pill.tsx`)

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

import { Pill } from "@/components/cobalt/ui/pill";
import { cn } from "@/lib/cobalt/utils";

const kinds = ["Papers", "Videos", "Talks", "Events"] as const;

type Kind = (typeof kinds)[number];

const items: { title: string; kind: Kind }[] = [
  { title: "Flood exposure in coastal mortgages", kind: "Papers" },
  { title: "Carbon pricing and bank lending", kind: "Papers" },
  { title: "Reading a 13F in ten minutes", kind: "Videos" },
  { title: "Private credit, two years on", kind: "Talks" },
  { title: "Autumn fund managers forum", kind: "Events" },
];

export default function Example() {
  const [chosen, setChosen] = useState<ReadonlySet<Kind>>(new Set<Kind>(["Papers"]));
  // Filters narrow the rows already loaded, so the list answers at once.
  const shown = items.filter((item) => chosen.size === 0 || chosen.has(item.kind));
  return (
    <div className="flex w-full max-w-sm flex-col gap-4">
      <div className="flex flex-wrap gap-1.5">
        {kinds.map((kind) => (
          <Pill
            key={kind}
            pressed={chosen.has(kind)}
            onPressedChange={(pressed) => {
              setChosen((was) => {
                const next = new Set(was);
                if (pressed) next.add(kind);
                else next.delete(kind);
                return next;
              });
            }}
          >
            {kind}
          </Pill>
        ))}
      </div>
      {/* The whole list sits invisible in the same cell, so the list keeps its tallest height and
          nothing below it moves as the filters change. */}
      <div className="grid">
        {[items, shown].map((rows, layer) => (
          <ul
            key={layer}
            aria-hidden={layer === 0 || undefined}
            className={cn("col-start-1 row-start-1 flex flex-col gap-2 text-sm", layer === 0 && "invisible")}
          >
            {rows.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">{item.kind}</span>
              </li>
            ))}
          </ul>
        ))}
      </div>
    </div>
  );
}
```

Example: Two tools over a note, each pressed for as long as it applies (`docs/system/examples/toggle/look-plain.tsx`)

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

import { Toggle } from "@/components/cobalt/ui/toggle";
import { cn } from "@/lib/cobalt/utils";

const NOTE =
  "Notes for the quarterly review. *Ask about the move into private credit* before the call with the fund's managers.";

export default function Example() {
  // Views of the note already here, so each answers at once.
  const [preview, setPreview] = useState(false);
  const [wrap, setWrap] = useState(true);
  return (
    <div className="flex w-full max-w-sm flex-col gap-3">
      <div className="flex items-center gap-1">
        <Toggle pressed={preview} onPressedChange={setPreview}>
          Preview
        </Toggle>
        <Toggle pressed={wrap} onPressedChange={setWrap}>
          Wrap lines
        </Toggle>
      </div>
      <p
        className={cn(
          "overflow-x-auto rounded-xl bg-muted px-3 py-2 text-sm",
          wrap ? "whitespace-normal" : "whitespace-nowrap",
          !preview && "font-mono text-muted-foreground",
        )}
      >
        {preview ? NOTE.replaceAll("*", "") : NOTE}
      </p>
    </div>
  );
}
```

### size
`Toggle` takes `size`. `Pill` is `--control` tall, and a chip is the pill at `--control-sm` through `className="min-h-(--control-sm)"`, as ChipRow and FilterBar draw it; it still takes a 44px tap through `touch-target`.
- `default`: `--control` tall (36px) and at least as wide, `text-sm`. Used at 0 call sites.
- `sm`: `--control-sm` tall (32px), for a toggle in a dense row such as a table toolbar. Used at 0 call sites.
- `lg`: `--control-lg` tall (40px). Used at 0 call sites.
- `icon`: a glyph alone in a square of `--control`, IconButton's size. Used at 0 call sites; the default example.
- `icon-sm`: a glyph alone in a square of `--control-sm`, for a dense header. Used at 0 call sites.
- `icon-lg`: a glyph alone in a square of `--control-lg`. Used at 0 call sites.

Example: Beside a list's heading, it adds the archived lists to the rows (`docs/system/examples/toggle/size-sm.tsx`)

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

import { Toggle } from "@/components/cobalt/ui/toggle";

const lists = [
  { name: "Reading list", archived: false },
  { name: "Q3 13F filings", archived: false },
  { name: "Q2 13F filings", archived: true },
  { name: "Climate risk papers", archived: false },
];

export default function Example() {
  // The archived rows are already loaded, so the list answers at once.
  const [archived, setArchived] = useState(false);
  const shown = lists.filter((list) => archived || !list.archived);
  return (
    <div className="flex w-full max-w-sm flex-col gap-2">
      <div className="flex items-center justify-between gap-3">
        <h3 className="text-sm font-medium">Lists</h3>
        <Toggle size="sm" pressed={archived} onPressedChange={setArchived}>
          Show archived
        </Toggle>
      </div>
      <ul className="flex flex-col gap-1 text-sm">
        {shown.map((list) => (
          <li key={list.name} className="flex justify-between gap-3">
            <span className="min-w-0 wrap-break-word">{list.name}</span>
            {list.archived && <span className="shrink-0 text-muted-foreground">Archived</span>}
          </li>
        ))}
      </ul>
    </div>
  );
}
```

Example: Tools in a dense header, each named by its tooltip, that add details to the rows (`docs/system/examples/toggle/size-icon-sm.tsx`)

```tsx
import { useState, type ReactNode } from "react";

import { ClockIcon, MapPinIcon } from "@/components/cobalt/icon";
import { Toggle } from "@/components/cobalt/ui/toggle";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/cobalt/ui/tooltip";

const events = [
  { name: "Fund managers forum", time: "09:30", place: "Lisbon" },
  { name: "Credit outlook briefing", time: "13:00", place: "Online" },
  { name: "Quarterly review", time: "16:00", place: "Oslo" },
];

// The name is the toggle's aria-label and the tooltip's text, so it is written once.
function Tool({
  name,
  pressed,
  onPressedChange,
  children,
}: {
  name: string;
  pressed: boolean;
  onPressedChange: (pressed: boolean) => void;
  children: ReactNode;
}) {
  return (
    <Tooltip>
      <TooltipTrigger
        render={<Toggle size="icon-sm" aria-label={name} pressed={pressed} onPressedChange={onPressedChange} />}
      >
        {children}
      </TooltipTrigger>
      <TooltipContent>{name}</TooltipContent>
    </Tooltip>
  );
}

export default function Example() {
  // Details of the rows already loaded, so each answers at once.
  const [times, setTimes] = useState(true);
  const [places, setPlaces] = useState(false);
  return (
    <div className="flex w-full max-w-sm flex-col gap-2">
      <div className="flex items-center justify-between gap-3">
        <h3 className="text-sm font-medium">This week</h3>
        <div className="flex items-center gap-1">
          <Tool name="Show times" pressed={times} onPressedChange={setTimes}>
            <ClockIcon />
          </Tool>
          <Tool name="Show places" pressed={places} onPressedChange={setPlaces}>
            <MapPinIcon />
          </Tool>
        </div>
      </div>
      <ul className="flex flex-col gap-1 text-sm">
        {events.map((event) => (
          <li key={event.name} className="flex justify-between gap-3">
            <span className="min-w-0 wrap-break-word">{event.name}</span>
            <span className="shrink-0 text-muted-foreground tabular-nums">
              {[times && event.time, places && event.place].filter(Boolean).join(", ")}
            </span>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| off | render, or `pressed={false}` | press to turn on, focus | the label or glyph in the ink, on no fill for a toggle and on the grey fill for a pill, `aria-pressed="false"` | test |
| pressed | `pressed`, `defaultPressed`, or a press | press to turn off | the ink fill with light text at the same weight and the same content, so the width does not change: measured 0px between off and pressed on a pill (G-09, .design-system/evidence/pill/after-fix-light-390.json) and 77.52px both on a toggle (.design-system/evidence/toggle/grow-390.json) | test |
| hover | pointer over, under `(hover: hover)` | press | off: the grey fill on a toggle, one step darker on a pill; pressed: the ink at 85 percent; the text never changes | by hand |
| focus-visible | keyboard focus | press with Space or Enter | the 2px ring, 2px outside the corner | by hand |
| active | pointer or key down | release to toggle | the `--hover` tint over the fill while the pointer or key is down | by hand |
| disabled | `disabled` | nothing; focus skips it | half opacity; the pointer lands on it and does nothing, so a double-click selects no text beside it; `aria-pressed` still read | test |
| expanded | `aria-expanded="true"` from a `PopoverTrigger` rendering a pill | close the popover | an off pill keeps the `--muted-hover` fill while open; a pressed pill keeps the ink | screenshot |

Example: Both looks pressed, in the ink fill with light text at the same width as off (`docs/system/examples/toggle/state-pressed.tsx`)

```tsx
import { Pill } from "@/components/cobalt/ui/pill";
import { Toggle } from "@/components/cobalt/ui/toggle";

export default function Example() {
  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap gap-1.5">
        <Pill defaultPressed>Articles</Pill>
        <Pill>Videos</Pill>
      </div>
      <div className="flex flex-wrap gap-1">
        <Toggle defaultPressed>Wrap lines</Toggle>
        <Toggle>Preview</Toggle>
      </div>
    </div>
  );
}
```

Example: Both looks, off and pressed, at half opacity; a press or a double-click does nothing (`docs/system/examples/toggle/state-disabled.tsx`)

```tsx
import { Pill } from "@/components/cobalt/ui/pill";
import { Toggle } from "@/components/cobalt/ui/toggle";

export default function Example() {
  return (
    <div className="flex flex-col gap-3">
      <div className="flex flex-wrap gap-1.5">
        <Pill disabled>Podcasts</Pill>
        <Pill disabled pressed>
          Events
        </Pill>
      </div>
      <div className="flex flex-wrap gap-1">
        <Toggle disabled>Preview</Toggle>
        <Toggle disabled defaultPressed>
          Wrap lines
        </Toggle>
      </div>
    </div>
  );
}
```

Example: The grey fill deepens while its popover is open, and turns to ink once a range applies (`docs/system/examples/toggle/expanded.tsx`)

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

import { Pill } from "@/components/cobalt/ui/pill";
import {
  Popover,
  PopoverContent,
  PopoverHeader,
  PopoverTitle,
  PopoverTrigger,
} from "@/components/cobalt/ui/popover";
import { SegmentedControl } from "@/components/cobalt/ui/segmented-control";

type Range = "any" | "week" | "month";

const ranges = [
  { value: "any", label: "Any" },
  { value: "week", label: "Week" },
  { value: "month", label: "Month" },
] as const;

// Counts for the events already loaded, so a choice answers at once.
const counts: Record<Range, number> = { any: 26, week: 3, month: 11 };

export default function Example() {
  const [range, setRange] = useState<Range>("any");
  return (
    <div className="flex items-center gap-3">
      <Popover>
        <PopoverTrigger render={<Pill pressed={range !== "any"} />}>Date</PopoverTrigger>
        <PopoverContent>
          <PopoverHeader>
            <PopoverTitle>Date</PopoverTitle>
          </PopoverHeader>
          <SegmentedControl label="Date" fill value={range} onChange={setRange} options={ranges} />
        </PopoverContent>
      </Popover>
      <p className="text-sm text-muted-foreground tabular-nums">{counts[range]} events</p>
    </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 control still takes the pointer, so a double-click never reaches the words behind it.
- Disabled and pressed: both show. The ink fill at half opacity, with `aria-pressed="true"` still read.
- Pressed and hover: pressed wins the fill. The ink goes to 85 percent and the text stays light, so the state still shows under the pointer.
- Off and hover: both show. A toggle takes the `--muted` fill and a pill steps to `--muted-hover`.
- Hover and focus-visible: both show. The ring is an outline and the fill is a background.
- Active and pressed: both show. The tint sits over the ink fill.
- Expanded and pressed: pressed wins. Both are the ink fill, so opening changes nothing.
- Expanded and off: expanded wins. The `--muted-hover` fill stays while the popover is open, pointer or not.

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

## Props

<!-- Props generated from registry/cobalt/ui/toggle.tsx, registry/cobalt/ui/pill.tsx with TypeScript by scripts/props-table.mjs -->
### Toggle

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `size?` | `"default" \| "sm" \| "lg" \| "icon" \| "icon-sm" \| "icon-lg"` | `"default"` | `default` `--control` tall (36px) and at least as wide; `sm` `--control-sm` tall (32px); `lg` `--control-lg` tall (40px); `icon` a glyph alone in a square of `--control`; `icon-sm` a glyph alone in a square of `--control-sm`; `icon-lg` a glyph alone in a square of `--control-lg`. |

Also accepts every native `<button>` attribute; from Base UI: `defaultPressed`, `disabled`, `nativeButton`, `onPressedChange`, `pressed`, `render`, `value`.

### Pill

| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children?` | `ReactNode` |  |  |
| `className?` | `string` |  |  |

Also accepts every native `<button>` attribute; from Base UI: `defaultPressed`, `disabled`, `nativeButton`, `onPressedChange`, `pressed`, `render`, `value`.

Every Base UI `Toggle` prop passes through both parts: `pressed` and `onPressedChange` for a controlled control, `defaultPressed` for one left to itself, `disabled`, `render`, `aria-*`, and `aria-label` for one that is only a glyph. `Toggle` adds `size`, the axis above; `toggleVariants` is exported for a host that must style another element the same way, and is not a reason to skip the component. `Pill` has no size; `pillClasses(on, className)` is its look for a link or a trigger that is not a `Pill`, and `pillLabel` cuts a text label the same way. `className` is merged last on both and is for placement, or a pill's chip height. `children` is the label.

## Usage

### When to use
- A filter or an option over content that you turn on and off, and any number can be on. Use `Pill`.
- A tool that stays pressed while it applies and is pressed again to stop, such as showing a list's dates, a preview or wrapped lines. Use `Toggle`, in a toolbar beside the content it changes.

### When not to use
- Exactly one of several must be pressed. Use SegmentedControl instead, a radio group.
- The choice navigates to a filtered page. Use ChipRow instead, links that wear `pillClasses`.
- The state only applies on Save. Use Checkbox instead; a toggle that waits for Save is a checkbox.
- The press starts an action. Use Button instead.
- The control is a setting with two sides that applies at once and is read as on or off, such as notifications. Use Switch instead.
- The press keeps a thing for later. Use SaveToggle instead.

### Rules
- `rule/toggle-icon-only-named`: When a toggle has only a glyph, give it `aria-label` and wrap it in a `Tooltip` whose text is exactly that name, instead of a bare icon, because the name is what a screen reader reads with pressed or not pressed, and `Toggle` has no development warning for a missing one as `Button` does. Evidence: principle wcag: 4.1.2 Name, role, value, a control exposes a name; person D11. Check: test `toggle.test.tsx`, an icon-only toggle carries its name in `aria-label`; review of every Toggle whose children are a glyph.
  - Don't: `<Toggle><CalendarIcon /></Toggle>`
  - Do: `<Tooltip><TooltipTrigger render={<Toggle size="icon" aria-label="Show filing dates" />}><CalendarIcon /></TooltipTrigger><TooltipContent>Show filing dates</TooltipContent></Tooltip>`
- `rule/toggle-label-holds`: When a toggle or a pill is pressed, keep the same `children` in both states, instead of swapping "Show archived" for "Hide archived", because the state is read from `aria-pressed`, a renamed control sounds like a different one, and the same label keeps the box the same width. Evidence: principle wcag: 4.1.2 Name, role, value, the state is a property, not a new name; measured the same label at rest and pressed, 77.52px both, width delta 0, .design-system/evidence/toggle/grow-390.json. Check: review of every ternary in a Toggle's or a Pill's children.
  - Don't: `<Toggle pressed={archived} onPressedChange={setArchived}>{archived ? "Hide archived" : "Show archived"}</Toggle>`
  - Do: `<Toggle pressed={archived} onPressedChange={setArchived}>Show archived</Toggle>`
- `rule/toggle-applies-at-once`: When a toggle or a pill is pressed, apply the state or the filter in `onPressedChange`, instead of holding it in a draft behind a Save or an "Apply" button, because a toggle button acts when pressed and a choice that waits for a submit is a checkbox. Evidence: principle platform: a toggle button applies on press, a checkbox applies on submit; principle heuristic: visibility of system status, the content changes as the control does. Check: review of every Toggle and every row of pills for a submit button beside it.
  - Don't: `<Pill pressed={draft.free} onPressedChange={(on) => setDraft({ ...draft, free: on })}>Free</Pill> <Button>Apply filters</Button>`
  - Do: `<Pill pressed={filters.free} onPressedChange={(on) => setFilters({ ...filters, free: on })}>Free</Pill>`
- `rule/toggle-one-of-several-is-segmented`: When exactly one of several toggles or pills must be pressed, use `SegmentedControl`, instead of tying their `pressed` values to one shared value so that pressing one turns the others off, because a single choice is a radio group with one tab stop and arrow keys, and a row of toggles is a row of independent buttons announced as pressed or not pressed. Evidence: person D31; principle platform: a radio group is one tab stop with arrow keys and carries `aria-checked`, toggle buttons are one tab stop each and carry `aria-pressed`. Check: review of every row of toggles or pills whose handlers set one shared value.
  - Don't: `{views.map((v) => <Pill key={v} pressed={view === v} onPressedChange={() => setView(v)}>{v}</Pill>)}`
  - Do: `<SegmentedControl label="View" value={view} onChange={setView} options={views.map((v) => ({ value: v, label: v }))} />`
- `rule/pill-popover-trigger-is-a-pill`: When a pill opens a popover of options, render it through `PopoverTrigger render={<Pill pressed={active} />}` with `pressed` set by whether the filter is applied, instead of a `Button` or `pressed={open}`, because the trigger then carries `aria-pressed` for the filter and `aria-expanded` for the popover, and `pillClasses` gives an open pill the `--muted-hover` fill so an open filter does not look like an applied one. Evidence: single use registry/cobalt/ui/filter-bar.tsx:256, the filter bar's trigger takes the pill's fill from whether its filter applies, never from whether it is open; principle wcag: 4.1.2 Name, role, value, the open state is exposed on the control that opens it. Check: lint trap/button-clone (scripts/check-system.mjs); review of every `PopoverTrigger` with a round class.
  - Don't: `<PopoverTrigger render={<Button variant="secondary" />}>Date</PopoverTrigger>`
  - Do: `<PopoverTrigger render={<Pill pressed={range !== null} />}>Date</PopoverTrigger>`

### Content
- Follows `rule/writing-heading-sentence-case`.
- `rule/toggle-label-names-the-tool`: When a toggle has a text label, write the tool or the thing it shows, such as "Preview" or "Show archived", in sentence case, instead of the state such as "On" or "Enabled", because the fill and `aria-pressed` say the state and the label only has to say what is being switched. Evidence: person D11; principle heuristic: match between system and the real world, the label is the tool's name. Check: review of every Toggle label; lint rule/ban-uppercase (scripts/check-system.mjs).
  - Don't: `<Toggle pressed={preview} onPressedChange={setPreview}>On</Toggle>`
  - Do: `<Toggle pressed={preview} onPressedChange={setPreview}>Preview</Toggle>`
- `rule/pill-label-is-the-value`: When a pill labels a filter, write the value it turns on, such as "Free" or "This week", in sentence case, instead of a verb phrase such as "Show free events", because the fill and `aria-pressed` say whether it is on and the label only has to say what. Evidence: person D11; principle heuristic: match between system and the real world, the label is the value as a user would say it. Check: review of every pill label; lint rule/ban-uppercase (scripts/check-system.mjs).
  - Don't: `<Pill>Show free events</Pill>`
  - Do: `<Pill>Free</Pill>`

### Anti-slop
- `rule/toggle-pressed-is-the-ink`: When a toggle or a pill is pressed, keep the ink fill `toggleVariants` and `pillClasses` give it, instead of an accent fill, a border or a ring through `className`, because colour has one job, the accent is for the view's one primary action, and the on state across the system is the ink fill with light text. Evidence: person D13; person D18. Check: lint rule/component-override on Toggle and Pill (scripts/check-system.mjs).
  - Don't: `<Pill pressed className="bg-primary text-primary-foreground ring-2 ring-primary">Free</Pill>`
  - Do: `<Pill pressed>Free</Pill>`
- `rule/pill-no-shadow-or-border`: When a pill or a toggle needs to stand out from the page, leave it on its own fill, instead of adding a shadow or a hairline through `className`, because both are flat controls and the fill already separates them from the page. Evidence: person D11; app 5/5 uses of `pillClasses` add no shadow or border, `registry/cobalt/ui/chip-row.tsx:193`, `registry/cobalt/ui/filter-bar.tsx:256`, `registry/cobalt/ui/filter-bar.tsx:511`, `registry/cobalt/ui/date-picker.tsx:622`, `registry/cobalt/ui/range-filter.tsx:99`. Check: lint rule/component-override on Pill and Toggle (scripts/check-system.mjs).
  - Don't: `<Pill className="shadow-sm ring-1 ring-border">Free</Pill>`
  - Do: `<Pill>Free</Pill>`

### Limits
- `rule/toggle-label-length`: When a label would run past 47 characters at 390px on a toggle, or 49 on a pill, shorten it to the tool or the value's name, because the label never wraps (`white-space: nowrap`), so one character more reaches the width of a 310px column and the label is cut with an ellipsis, read whole only in the tooltip, which touch never shows. Evidence: measured clip at 48 characters on a toggle, .design-system/evidence/toggle/grow-390.json; measured overflow at 50 characters on a pill, .design-system/evidence/pill/grow-390.json. The cut, with the whole label in the tooltip, measured at 320px, docs/research/2026-10-16-break-ui-display.md. Check: probe `.design-system/scripts/grow-actions.mjs toggle` and `.design-system/scripts/grow-actions.mjs pill` on the showcase at 390.
  - Don't: `<Toggle>Show the archived items from every project and year</Toggle>`
  - Do: `<Toggle>Show archived</Toggle>`

## Accessibility
Rests on `<button type="button">` from Base UI `Toggle`, which sets `aria-pressed`, for both looks.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the control | focuses it and shows the ring | the control | by hand |
| Space or Enter | the control | toggles it and calls `onPressedChange` | the control | by hand |
| Space or Enter | a pill rendering a `PopoverTrigger` | opens the popover | the popover's first focusable, or the pill | by hand |
| Tab | a disabled control | skips it | the next control | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | button | `children`, the label; `aria-label` when the content is a glyph | `aria-pressed` true or false; `disabled`; `aria-expanded` from a popover trigger | the name, "toggle button" and pressed or not pressed, in the screen reader's words; the change on each press | test |
| glyph | none | the icon's own `aria-hidden` | none | nothing | by hand |

Contrast, measured in the showcase's example frame: a toggle off 19.8 to 1 (ink on the frame), pressed 18.47 to 1 (page tint on ink), disabled off 3.71 to 1 at half opacity, .design-system/evidence/toggle/grow-390.json; a pill off 17.03 to 1 (ink on `--muted`), pressed 18.47 to 1, disabled off 3.66 to 1 and disabled pressed 1.99 to 1, .design-system/evidence/pill/grow-390.json. A disabled control is exempt from the 4.5 to 1 minimum (WCAG 1.4.3), and its state is read from `aria-pressed`.

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--control-sm`, `--control`, `--control-lg`, `--r-control`, `--t-press`, `--curve`, `--ring`; `--touch` under a coarse pointer on a pill and on `icon-sm` |
| root | off, pill | `--muted`, `--foreground` |
| root | off, pill, hover and expanded | `--muted-hover` |
| root | off, plain, hover | `--muted`, `--foreground` |
| root | pressed | `--foreground` as the fill, `--background` as the text |
| root | pressed, hover | `--foreground` at 85 percent |
| glyph | all | `--foreground` through `currentColor`, 16px (`size-4`) |

## Related
- SegmentedControl: exactly one of a few, a radio group.
- ChipRow: links that wear the pill's look, for a choice that navigates.
- FilterBar: filter pills over a list, each naming what is chosen, that fold into one sheet on a phone.
- Switch: a setting with two sides, read as on or off.
- Checkbox: a choice that applies on Save.
- SaveToggle: keeps a thing for later instead of filtering a list.
- IconButton: 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.
- Button: a press that starts an action.
- StateButton: an action that reports its request inside the button.
