# Actions & buttons

One primary action per surface, the rest quieter, and the rare ones in a menu. A button's look says how much it matters.

API [Button](/ui/storybook/?path=/docs/ui-primitives-button--docs) [SegmentedControl](/ui/storybook/?path=/docs/ui-primitives-segmentedcontrol--docs) [DropdownMenu](/ui/storybook/?path=/docs/ui-primitives-dropdownmenu--docs) [Tooltip](/ui/storybook/?path=/docs/ui-primitives-tooltip--docs) [Textarea](/ui/storybook/?path=/docs/ui-primitives-textarea--docs) [Badge](/ui/storybook/?path=/docs/ui-primitives-badge--docs) [ConfirmDialog](/ui/storybook/?path=/docs/ui-confirmdialog--docs) [SelectionBar](/ui/storybook/?path=/docs/ui-selectionbar--docs) [Checkbox](/ui/storybook/?path=/docs/ui-primitives-checkbox--docs) [Table](/ui/storybook/?path=/docs/ui-primitives-table--docs) [List](/ui/storybook/?path=/docs/ui-primitives-list--docs) [useSelection](/ui/storybook/?path=/docs/ui-hooks-useselection--docs) [useSweepSelect](/ui/storybook/?path=/docs/ui-hooks-usesweepselect--docs) [SelectionAction](/ui/storybook/?path=/docs/ui-selectionaction--docs) [useScrollInsets](/ui/storybook/?path=/docs/ui-hooks-usescrollinsets--docs) [AttachmentList](/ui/storybook/?path=/docs/ui-content-attachmentlist--docs)

**A surface has at most one primary button: the action most people came to take. Everything else steps down a variant, and actions used now and then move into a menu.**

```tsx
import { INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { Badge } from "@orz/ui/components/badge";
import { Button } from "@orz/ui/components/button";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuTrigger,
} from "@orz/ui/components/dropdown-menu";
import { Kbd } from "@orz/ui/components/kbd";
import { Pane } from "@orz/ui/components/pane";
import { Textarea } from "@orz/ui/components/textarea";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  ArchiveIcon,
  EllipsisIcon,
  ForwardIcon,
  InboxIcon,
  LinkIcon,
  type LucideIcon,
  SendIcon,
  Trash2Icon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const thread = INBOX_THREADS.find(({ id }) => id === "touch-sizes");

type Folder = "Inbox" | "Archive" | "Trash";

const ACTIONS: {
  label: string;
  key?: string;
  icon: LucideIcon;
  to: Folder;
  from: Folder[];
}[] = [
  {
    label: "Archive",
    key: "E",
    icon: ArchiveIcon,
    to: "Archive",
    from: ["Inbox"],
  },
  {
    label: "Move to Inbox",
    icon: InboxIcon,
    to: "Inbox",
    from: ["Archive", "Trash"],
  },
  {
    label: "Delete",
    key: "#",
    icon: Trash2Icon,
    to: "Trash",
    from: ["Inbox", "Archive"],
  },
];

const MOVED: Record<Folder, string> = {
  Inbox: "Conversation moved to Inbox",
  Archive: "Conversation archived",
  Trash: "Conversation moved to Trash",
};

export function ThreadActions() {
  const [folder, setFolder] = useState<Folder>("Inbox");
  const [reply, setReply] = useState("");
  const move = (to: Folder) => {
    const was = folder;
    setFolder(to);
    toast(MOVED[to], {
      action: { label: "Undo", onClick: () => setFolder(was) },
    });
  };
  return (
    <TooltipProvider>
      <div className="grid gap-3">
        <Pane purpose="toolbar" className="flex items-center gap-0.5 px-1.5">
          {ACTIONS.filter(({ from }) => from.includes(folder)).map(
            ({ label, key, icon: Icon, to }) => (
              <Tooltip key={label}>
                <TooltipTrigger asChild>
                  <ToolbarButton aria-label={label} onClick={() => move(to)}>
                    <Icon />
                  </ToolbarButton>
                </TooltipTrigger>
                <TooltipContent>
                  {label} {key && <Kbd>{key}</Kbd>}
                </TooltipContent>
              </Tooltip>
            ),
          )}
          <DropdownMenu>
            <Tooltip>
              <TooltipTrigger asChild>
                <DropdownMenuTrigger asChild>
                  <ToolbarButton className="ml-auto" aria-label="More actions">
                    <EllipsisIcon />
                  </ToolbarButton>
                </DropdownMenuTrigger>
              </TooltipTrigger>
              <TooltipContent>More actions</TooltipContent>
            </Tooltip>
            <DropdownMenuContent align="end" className="w-44">
              <DropdownMenuItem>
                <ForwardIcon />
                Forward
              </DropdownMenuItem>
              <DropdownMenuItem onSelect={() => toast("Link copied")}>
                <LinkIcon />
                Copy link
              </DropdownMenuItem>
            </DropdownMenuContent>
          </DropdownMenu>
        </Pane>
        <div className="flex flex-wrap items-center gap-2">
          <h3 className="font-semibold">{thread?.subject}</h3>
          {folder !== "Inbox" && <Badge variant="outline">{folder}</Badge>}
        </div>
        <form
          className="flex items-end gap-2"
          onSubmit={(event) => {
            event.preventDefault();
            setReply("");
            toast("Reply sent");
          }}
        >
          <Textarea
            aria-label="Reply"
            placeholder="Reply in markdown…"
            value={reply}
            onChange={(event) => setReply(event.target.value)}
            className="min-h-10 flex-1"
          />
          <Button type="submit" disabled={reply.trim() === ""}>
            <SendIcon />
            Send
          </Button>
        </form>
      </div>
    </TooltipProvider>
  );
}
```

A conversation from the Mail demo. **Send** is the one primary button, and it waits until there is a reply to send. Archive and Delete are ghost icon buttons, each with a name, and a tooltip that also shows its key. Forward and Copy link are used now and then, so they wait behind **More actions**. Archive or delete the conversation: the toolbar swaps in **Move to Inbox**, and the toast takes it back.

## Do and don't

**Do**

Make the action people came for the one primary button, and step the others down.

**Don't**

Give every action the primary look: nothing stands out, so people read every label to find the one they want.

**Do**

Label a button with a verb and its object, "Save profile", "Delete 3 files", so it still reads right out of context.

**Don't**

Label it "OK", "Submit" or "Yes": the button then only makes sense after reading the question above it.

## Which variant

| The action                                                                                | `variant`                                                                                      |
| ----------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------- |
| The one action the surface exists for: Save, Publish, Send                                | `default`                                                                                      |
| A second action nearly as wanted, which the reader may take instead: Save draft, Schedule | `secondary`                                                                                    |
| An alternative or a way back beside it: Cancel, Back, Discard changes                     | `outline`                                                                                      |
| A repeated or toolbar action, usually an icon: Bold, Copy, Close                          | `ghost`                                                                                        |
| An action that deletes or discards                                                        | `destructive`, see [Destructive actions](/ui/guidelines/patterns/destructive-actions/index.md) |
| A navigation that looks like a link inside prose or a table                               | `link`, or a real `<a>` through `asChild`                                                      |

The variants rank. `default` is the primary itself, its words reversed out of it; `secondary` is a tint of the primary, edged in it, so it reads as an action of the same kind one step down; `outline` is a grey key, which any surface can hold several of; `ghost` is bare until the pointer reaches it. `destructive` is `secondary` in the destructive colour.

```tsx
import { TOKENS } from "@orz/fixtures/account.ts";
import { CI_RUN } from "@orz/fixtures/ci-run.ts";
import { Button } from "@orz/ui/components/button";
import { Separator } from "@orz/ui/components/separator";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  ArchiveIcon,
  CircleXIcon,
  KeyRoundIcon,
  MailIcon,
  Trash2Icon,
} from "lucide-react";

const [token] = TOKENS;

const TOOLBAR = [
  { label: "Archive", icon: ArchiveIcon },
  { label: "Delete", icon: Trash2Icon },
  { label: "Mark as unread", icon: MailIcon },
];

export function ButtonVariants() {
  return (
    <TooltipProvider>
      <div className="grid">
        <div className="flex flex-wrap items-center justify-end gap-2 pb-4 touch:gap-y-[calc(2*var(--spacing-hit))]">
          <span className="mr-auto font-mono text-muted-foreground text-ui-sm">
            default, outline
          </span>
          <Button variant="outline">Discard changes</Button>
          <Button>Save profile</Button>
        </div>
        <Separator />
        <div className="flex items-center gap-0.5 py-4">
          <span className="mr-auto font-mono text-muted-foreground text-ui-sm">
            ghost
          </span>
          {TOOLBAR.map(({ label, icon: Icon }) => (
            <Tooltip key={label}>
              <TooltipTrigger asChild>
                <ToolbarButton aria-label={label}>
                  <Icon />
                </ToolbarButton>
              </TooltipTrigger>
              <TooltipContent>{label}</TooltipContent>
            </Tooltip>
          ))}
        </div>
        <Separator />
        <div className="flex items-center gap-3 py-4">
          <span className="font-mono text-muted-foreground text-ui-sm">
            destructive
          </span>
          <KeyRoundIcon className="ml-auto size-4 shrink-0 text-muted-foreground" />
          <span className="truncate font-medium font-mono text-ui">
            {token?.name}
          </span>
          <Button
            variant="destructive"
            size="sm"
            aria-label={`Revoke ${token?.name}`}
          >
            Revoke…
          </Button>
        </div>
        <Separator />
        <div className="flex items-center gap-2 pt-4 text-ui">
          <span className="mr-auto font-mono text-muted-foreground text-ui-sm">
            link
          </span>
          <CircleXIcon className="size-4 text-destructive" />
          <span>
            {CI_RUN.workflow} #{CI_RUN.id} {CI_RUN.status}
          </span>
          <Button variant="link" size="sm" className="h-auto px-0" asChild>
            <a href="#checks">Details</a>
          </Button>
        </div>
      </div>
    </TooltipProvider>
  );
}
```

Each row is taken from a demo: the Settings profile form's footer, the Mail toolbar, an access token's row, and a failed run on the pull request's timeline, whose **Details** is a link.

The size follows the surface rather than the action: `default` in forms and dialogs, `sm` in dense rows and table cells, and `lg` only for a call to action that stands alone.

An action that leaves the page is a link (`<Button asChild><a href>…</a></Button>`), so it opens in a new tab and shows its address; an action that changes something is a button.

## A verdict in colour

An action whose outcome is good, risky or a loss in itself, such as approving, asking for changes or rejecting, can say so in colour as well as in words: `intent` stands the palette's `success`, `warning` or `destructive` (`danger`) colour in for the primary, in whichever variant the button has. `default` is filled with it, its words reversed out of it; `secondary` is its tint, edged in it, its words in its ink; `outline` and `ghost` keep their own look, with the icon in the colour. A `DropdownMenuItem` takes the same `intent`, its words and its icon in the colour, so a verdict offered in a menu reads as it does on a button, and a toolbar command or segment that moves into the `⋯` keeps its colour there.

```tsx
import { PULL_REQUEST } from "@orz/fixtures/pull-request.ts";
import { Badge } from "@orz/ui/components/badge";
import { Button } from "@orz/ui/components/button";
import { CheckIcon, RotateCcwIcon, XIcon } from "lucide-react";
import { useState } from "react";

type Decision = "approved" | "changes" | "rejected";

const DECIDED = {
  approved: { intent: "success", icon: CheckIcon, words: "Approved" },
  changes: {
    intent: "warning",
    icon: RotateCcwIcon,
    words: "Changes requested",
  },
  rejected: { intent: "danger", icon: XIcon, words: "Rejected" },
} as const;

export function DecideReview() {
  const [decision, setDecision] = useState<Decision | null>(null);
  const decided = decision && DECIDED[decision];
  return (
    <div className="grid gap-3">
      <div className="flex flex-wrap items-center gap-2 text-ui">
        <span className="min-w-0 truncate font-medium">
          {PULL_REQUEST.title}
        </span>
        <span className="text-muted-foreground">#{PULL_REQUEST.number}</span>
        {decided && (
          <Badge intent={decided.intent} className="ml-auto">
            <decided.icon /> {decided.words}
          </Badge>
        )}
      </div>
      <div className="flex flex-wrap gap-2">
        <Button intent="success" onClick={() => setDecision("approved")}>
          <CheckIcon /> Approve
        </Button>
        <Button
          variant="secondary"
          intent="warning"
          onClick={() => setDecision("changes")}
        >
          <RotateCcwIcon /> Request changes
        </Button>
        <Button
          variant="secondary"
          intent="danger"
          onClick={() => setDecision("rejected")}
        >
          <XIcon /> Reject
        </Button>
      </div>
    </div>
  );
}
```

Where the view is for deciding and each button takes effect the moment it is pressed, the verdict the view expects is the one primary, in its colour, and the others step down to `secondary` in theirs. Press one: the review is decided at once, and its badge says how.

```tsx
import { PULL_REQUEST } from "@orz/fixtures/pull-request.ts";
import { Badge } from "@orz/ui/components/badge";
import { Button } from "@orz/ui/components/button";
import {
  SegmentedControl,
  SegmentedControlItem,
} from "@orz/ui/components/segmented-control";
import { Textarea } from "@orz/ui/components/textarea";
import { CheckIcon, RotateCcwIcon, XIcon } from "lucide-react";
import { useState } from "react";

const VERDICTS = {
  approve: {
    intent: "success",
    icon: CheckIcon,
    choice: "Approve",
    sent: "Approved",
  },
  changes: {
    intent: "warning",
    icon: RotateCcwIcon,
    choice: "Request changes",
    sent: "Changes requested",
  },
  reject: {
    intent: "danger",
    icon: XIcon,
    choice: "Reject",
    sent: "Rejected",
  },
} as const;

type Verdict = keyof typeof VERDICTS;

export function ReviewVerdict() {
  const [verdict, setVerdict] = useState<Verdict>("changes");
  const [sent, setSent] = useState<Verdict | null>(null);
  const shown = sent && VERDICTS[sent];
  return (
    <div className="grid gap-3">
      <div className="flex flex-wrap items-center gap-2 text-ui">
        <span className="min-w-0 truncate font-medium">
          {PULL_REQUEST.title}
        </span>
        <span className="text-muted-foreground">#{PULL_REQUEST.number}</span>
        {shown && (
          <Badge intent={shown.intent} className="ml-auto">
            <shown.icon /> {shown.sent}
          </Badge>
        )}
      </div>
      <Textarea
        aria-label="Review comment"
        rows={3}
        defaultValue="Could a status error skip the second attempt?"
      />
      <div className="flex flex-wrap items-center gap-2">
        <SegmentedControl
          aria-label="Verdict"
          value={verdict}
          onValueChange={(next) => setVerdict(next as Verdict)}
        >
          {(Object.keys(VERDICTS) as Verdict[]).map((key) => {
            const { intent, icon: Icon, choice } = VERDICTS[key];
            return (
              <SegmentedControlItem key={key} value={key} intent={intent}>
                <Icon /> {choice}
              </SegmentedControlItem>
            );
          })}
        </SegmentedControl>
        <Button className="ml-auto" onClick={() => setSent(verdict)}>
          Submit review
        </Button>
      </div>
    </div>
  );
}
```

Where the verdict is chosen and then sent with something else, a comment here, it is not an action yet: it is a `SegmentedControl` whose segments carry the intents, the chosen one held in its colour's tint, and the one primary is **Submit review**, in the primary's own colour. Nothing happens until it is pressed, and the verdict can change until then.

- Give an intent to an action whose result is itself good news, a risk or a loss. Most buttons have none: Save is not a success, and a red that means "important" teaches people to ignore the red that means "gone".
- The words carry the verdict, and the colour backs them up: "Approve", "Request changes", "Reject", never three coloured "OK"s.
- An action that deletes stays `destructive`, which is `secondary` in the `danger` intent, as [Destructive actions](/ui/guidelines/patterns/destructive-actions/index.md) describes.

## Overflow

Put the actions a surface offers but people rarely take into a `DropdownMenu` behind a ghost icon button named "More actions". Keep the order stable: frequent first, destructive last behind a separator, each with `variant="destructive"`.

```tsx
import { INBOX_THREADS } from "@orz/fixtures/inbox.ts";
import { ConfirmDialog } from "@orz/ui/components/confirm-dialog";
import {
  DropdownMenu,
  DropdownMenuContent,
  DropdownMenuItem,
  DropdownMenuSeparator,
  DropdownMenuTrigger,
} from "@orz/ui/components/dropdown-menu";
import { Pane } from "@orz/ui/components/pane";
import { ToolbarButton } from "@orz/ui/components/toolbar";
import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@orz/ui/components/tooltip";
import {
  EllipsisIcon,
  ForwardIcon,
  LinkIcon,
  Trash2Icon,
  Undo2Icon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const thread = INBOX_THREADS.find(({ folder }) => folder === "trash");

export function TrashThreadMenu() {
  const [confirming, setConfirming] = useState(false);
  return (
    <TooltipProvider>
      <div className="grid gap-3">
        <Pane purpose="toolbar" className="flex items-center gap-0.5 px-1.5">
          <Tooltip>
            <TooltipTrigger asChild>
              <ToolbarButton aria-label="Move to Inbox">
                <Undo2Icon />
              </ToolbarButton>
            </TooltipTrigger>
            <TooltipContent>Move to Inbox</TooltipContent>
          </Tooltip>
          <DropdownMenu>
            <Tooltip>
              <TooltipTrigger asChild>
                <DropdownMenuTrigger asChild>
                  <ToolbarButton className="ml-auto" aria-label="More actions">
                    <EllipsisIcon />
                  </ToolbarButton>
                </DropdownMenuTrigger>
              </TooltipTrigger>
              <TooltipContent>More actions</TooltipContent>
            </Tooltip>
            <DropdownMenuContent align="end" className="w-44">
              <DropdownMenuItem>
                <ForwardIcon />
                Forward
              </DropdownMenuItem>
              <DropdownMenuItem onSelect={() => toast("Link copied")}>
                <LinkIcon />
                Copy link
              </DropdownMenuItem>
              <DropdownMenuSeparator />
              <DropdownMenuItem
                variant="destructive"
                onSelect={() => setConfirming(true)}
              >
                <Trash2Icon />
                Delete forever…
              </DropdownMenuItem>
            </DropdownMenuContent>
          </DropdownMenu>
        </Pane>
        <h3 className="font-semibold">{thread?.subject}</h3>
      </div>
      <ConfirmDialog
        open={confirming}
        onOpenChange={setConfirming}
        title={`Delete “${thread?.subject}” forever?`}
        description="It cannot be restored. To keep it, move it back to the inbox instead."
        confirmLabel="Delete forever"
        destructive
        onConfirm={() => {
          setConfirming(false);
          toast("Conversation deleted forever");
        }}
      />
    </TooltipProvider>
  );
}
```

A conversation in Mail's Trash. Open **More actions**: Forward and Copy link come first, and **Delete forever…** waits last, after a separator, in the destructive colour. Its ellipsis says it asks before it acts.

Do not hide the primary action in a menu, and do not put a single action in one: a menu with one item is a button that costs two taps.

## Acting on a selection

A list or tree whose rows can be selected heads them with a `SelectionBar`, a toolbar that starts with a select-all checkbox. While nothing is selected it holds the list's own toolbar; once a row is selected it says how many, offers the actions that take the whole selection, and ends with **Clear selection**.

```tsx
import {
  INBOX_LABEL_COLORS,
  INBOX_THREADS,
  type InboxThread,
} from "@orz/fixtures/inbox.ts";
import { Badge } from "@orz/ui/components/badge";
import {
  FilterMenu,
  MatchedText,
  matchText,
} from "@orz/ui/components/filter-menu";
import { Frame } from "@orz/ui/components/frame";
import { List, ListItem, ListItemSelect } from "@orz/ui/components/list";
import { SelectionBar } from "@orz/ui/components/selection-bar";
import {
  ToolbarButton,
  ToolbarItem,
  ToolbarLabel,
} from "@orz/ui/components/toolbar";
import { useSelection } from "@orz/ui/hooks/use-selection";
import { cn } from "@orz/ui/lib/utils";
import {
  ArchiveIcon,
  MailIcon,
  MailOpenIcon,
  TagIcon,
  Trash2Icon,
} from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";

const THREADS = INBOX_THREADS.filter(({ folder }) => folder === "inbox").slice(
  0,
  4,
);
const LABELS = [...new Set(THREADS.flatMap((thread) => thread.labels))];

// The frame's corner drags it narrower: the actions give up their words,
// then go into the ⋯, as the bar's own width asks.
export function SelectedThreads() {
  const [threads, setThreads] = useState(THREADS);
  const selection = useSelection(
    threads.map(({ id }) => id),
    { defaultSelected: [THREADS[1]?.id ?? ""] },
  );
  const count = selection.selected.length;
  const [query, setQuery] = useState("");
  // The threads as the menu opened, which a label partly picked goes back to.
  const [opened, setOpened] = useState(threads);
  const chosen = threads.filter(({ id }) => selection.isSelected(id));
  const anyUnread = chosen.some((thread) => thread.unread);
  const labelled = (label: string) =>
    chosen.filter((thread) => thread.labels.includes(label)).length;
  const act = (verb: string) => {
    toast(`${count} ${count === 1 ? "conversation" : "conversations"} ${verb}`);
    selection.clear();
  };
  const change = (each: (thread: InboxThread) => Partial<InboxThread>) =>
    setThreads((all) =>
      all.map((thread) =>
        selection.isSelected(thread.id)
          ? { ...thread, ...each(thread) }
          : thread,
      ),
    );
  return (
    <Frame inset className="w-xl min-w-48 max-w-full resize-x overflow-hidden">
      <SelectionBar
        aria-label="Inbox"
        edge="bottom"
        count={count}
        total={threads.length}
        onSelectAll={selection.toggleAll}
        onClear={selection.clear}
        idle={
          <ToolbarItem flex minWidth={80}>
            <span className="truncate px-1 font-medium">Inbox</span>
          </ToolbarItem>
        }
      >
        <ToolbarButton aria-label="Archive" onClick={() => act("archived")}>
          <ArchiveIcon />
        </ToolbarButton>
        <ToolbarButton aria-label="Delete" onClick={() => act("deleted")}>
          <Trash2Icon />
        </ToolbarButton>
        <FilterMenu
          selection="multiple"
          selectedIds={LABELS.filter(
            (label) => labelled(label) === chosen.length,
          )}
          mixedIds={LABELS.filter(
            (label) => labelled(label) > 0 && labelled(label) < chosen.length,
          )}
          onOpenChange={(open) => {
            if (open) setOpened(threads);
          }}
          query={query}
          onQueryChange={setQuery}
          sections={[
            {
              id: "labels",
              rows: LABELS.filter((label) => matchText(label, query)).map(
                (label) => ({ id: label }),
              ),
            },
          ]}
          onSelect={(row, event) =>
            change((thread) => {
              const was = opened.find(({ id }) => id === thread.id);
              const on = event.mixed
                ? (was?.labels.includes(row.id) ?? false)
                : event.selected;
              return {
                labels: LABELS.filter((label) =>
                  label === row.id ? on : thread.labels.includes(label),
                ),
              };
            })
          }
          renderRow={(row, state) => (
            <MatchedText text={row.id} query={state.query} />
          )}
          placeholder="Filter labels…"
          inputLabel="Filter labels"
          listLabel="Labels"
        >
          <ToolbarButton>
            <TagIcon />
            <ToolbarLabel>Labels</ToolbarLabel>
          </ToolbarButton>
        </FilterMenu>
        <ToolbarButton onClick={() => change(() => ({ unread: !anyUnread }))}>
          {anyUnread ? <MailOpenIcon /> : <MailIcon />}
          <ToolbarLabel>
            {anyUnread ? "Mark as read" : "Mark as unread"}
          </ToolbarLabel>
        </ToolbarButton>
      </SelectionBar>
      <List purpose="listbox" selection={selection}>
        <ul>
          {threads.map((thread) => (
            <ListItem asChild key={thread.id} value={thread.id}>
              <li className="flex min-h-row items-center gap-3 px-3 py-1.5">
                <ListItemSelect aria-label={`Select “${thread.subject}”`} />
                <span
                  className={cn(
                    "min-w-0 flex-1 truncate",
                    thread.unread && "font-semibold",
                  )}
                >
                  {thread.unread && <span className="sr-only">Unread: </span>}
                  {thread.subject}
                </span>
                {thread.labels.map((label) => (
                  <Badge
                    key={label}
                    variant="marker"
                    color={INBOX_LABEL_COLORS[label]}
                  >
                    {label}
                  </Badge>
                ))}
              </li>
            </ListItem>
          ))}
        </ul>
      </List>
    </Frame>
  );
}
```

Select a second conversation, then press the checkbox in the bar: a partly checked box selects the rest, and a full one clears. Escape inside the bar clears too, and the focus stays on the checkbox. Drag the frame's corner narrower: the actions drop their words, then go into the `⋯`, while the checkbox, the count and **Clear selection** stay.

- Pass the parts of the list's toolbar as `idle`, and the actions as the bar's children: `ToolbarButton`s, a `ToolbarMenu`, a `FilterMenu`, as a [toolbar](/ui/guidelines/patterns/toolbars/index.md) takes them. They give way as its commands do, and the bar stays one Tab stop and one height whether or not anything is selected.
- Put only the actions that apply to every selected row in the bar, icons first, a text action such as **Delete forever…** after them. The bar swaps them as the selection changes, as Mail's swaps **Archive** for **Move to Inbox** when the selection is archived.
- An action that uses the selection up, as **Archive** does, or a **Set status** that moves the rows out of the list, clears the selection once it is done. The focus goes to the checkbox wherever in the bar the action was, on the bar, in its menu or in the `⋯`, rather than falling to the page.
- A list with no toolbar of its own mounts the bar only while something is selected. It is still there: on a touch screen, once a row is selected a tap selects too, and the bar's **Clear selection** is the visible way back.
- An action on the whole list, such as **Download all**, sits at the end of the bar while nothing is selected, and gives way to the actions on the selection once something is: the selection is then what an action takes. An `AttachmentList` takes the first as `listActions` and the second as `selectionActions`; an action on one file stays on its row, as `actions`.
- Select-all selects the rows the list holds now, never the ones still behind **Load more**.

A list that is not a `Tree` keeps its selection in `useSelection`, which feeds the bar its count and its select-all, and drops a row from the selection the moment the row leaves the list, so an action never reaches a row the reader no longer sees. A `Table` or a `List` takes it as `selection`: each row gives its key as `value`, its box is a `TableRowSelect` or a `ListItemSelect`, and a table's header box, or a group heading's, is a `TableHeadSelect`.

- Shift-click selects a range: every row from the last one clicked to this one takes this one's new state, as in a file manager. Space on a box ticks it too.
- A mouse selects many rows at once by sweeping: a press on a box dragged across the other rows selects every row the pointer crosses, anywhere on the row, or clears them when the first box was checked. Held at the edge of what scrolls, it scrolls on, and the rows it brings in count too. It starts only on a box, so a drag across a row's text still selects the text, and on touch the same drag still scrolls. `Board`, `Tree` and `AttachmentList` sweep on their own, as a `Table` and a `List` given a `selection` do; `useSweepSelect` is for a view the app draws itself.
- Where a row leads with an icon, a `SelectSlot` lets the checkbox stand in for it, as a `Tree`'s does: the icon until the pointer is on the row, the box from then on and on every selected row, and on touch on every row once anything is selected. The icon is the box's hit area, so a tap on it selects.

## Acting on selected text

An action that takes the words the reader picked out, such as **Quote reply** on a comment, comes to the selection with `SelectionAction`: under its last line for a mouse, or over its first when the window ends below it, and on a touch screen as a bar along the window's foot, where the platform's own bubble cannot cover it. The Pull request demo quotes a comment into the reply box this way.

- Register each place a selection means something, a comment's body, with `useSelectionRegion`. A selection that runs out of it, into the comment's header or the next comment, offers nothing: the action would not know whose words they are.
- A page that holds one document and nothing else to act on, a file's own view, may let its region take a selection that runs past its edge, with `overflow: "clamp"`: a drag on past the end of the file, or Select All, then acts on the file up to its edge. The action is told which ends were moved there (`clamped`), since such an end lies between blocks rather than in a word. Where regions sit side by side, as comments in a timeline do, keep the default.
- Regions drawn in a second window, such as a Picture-in-Picture window, go inside a `PortalContainerContext` with that window's `document.body`, the action with them (see [Overlays](/ui/guidelines/patterns/overlays/index.md#in-another-window)). It then reads the selection made there and stays inside that window, clear of the bars its own `scroll-padding` marks.
- Offer one or two actions, the ones selecting the text was for. Copying is the platform's already.
- Where a selection inside the region leaves the action nothing to work with, words that map to no line it could point at, offer nothing: return `null` rather than a disabled button.
- On a page with a sticky header or toolbar, declare it with `useScrollInsets`, as the page's own landings need anyway: the floating action then never covers the bar, and a selection scrolled under the bar takes the action under with it.
- The floating action is a shortcut for a pointer. Where the keyboard needs the action too, keep it in the comment's menu as well: selecting text from the keyboard leaves no pointer to press it with.

## On each platform

### Desktop & pointer

- An icon-only button has an `aria-label`, and a `Tooltip` that shows the same name on hover and on keyboard focus.
- A frequent action gets a keyboard shortcut, shown in its tooltip or menu item (`DropdownMenuShortcut`).
- Enter submits a form's primary action; Escape cancels a dialog, so neither needs a mouse.

### Touch

- Tooltips do not open on touch. The `aria-label` still names the button for a screen reader, but an icon whose meaning is not obvious needs a text label on a phone.
- Buttons take their touch sizes by themselves. Keep a row of them from wrapping into a second row that pushes content down: move the rare ones into the overflow menu instead.
- In a dialog footer on a narrow screen the buttons stack full width, the primary one on top, within reach of a thumb.

## In the demos

- [Settings](/ui/demos/settings/index.md): Profile ends in one primary button, Save profile, with Discard changes outlined beside it. Revoke… repeats on every token, so it is a size down.
- [Tasks](/ui/demos/tasks/index.md): New task… is the one primary button. Each row's ⋯ holds the actions on that task, and the bulk bar names its actions with their count once tasks are selected: press a row's box and drag down the others to select them all.
- [Mail](/ui/demos/mail/index.md): Compose is the one primary button. The toolbars are ghost icon buttons with tooltips, and the rare actions (Forward, Copy link) wait behind More actions.
- [Notes](/ui/demos/notes/index.md): New note is the list's one action. Delete note waits in More actions, last, after a separator.
