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

## Description
Takes you to another page from a word inside a sentence or beside a heading, such as "See all".

`import { TextLink } from "@/components/cobalt/ui/text-link"`, source `registry/cobalt/ui/text-link.tsx`, status `ready-with-gaps`.
Foundation: `hand-rolled`. Traps checked: `trap/link-as-button` (Usage, `rule/text-link-is-an-anchor`: it renders an `<a href>`, and the Button `link` variant it replaces rendered a `<button>`), `trap/link-cue` (States, default: the accent ink is the resting cue, and the underline comes under the pointer), `trap/weight-shift` (States, hover: the underline adds no width and the weight stays the text's own), `trap/focus-ring-shape` (States, focus-visible: the global outline follows the 6px corner), `trap/external-glyph-internal` (n/a, it adds no glyph), `trap/reduced-motion-ignored` (Motion: Not applicable, it has no transition).

### Foundation
| Given by the foundation | Added by the team |
|---|---|
| Not applicable: hand-rolled | An `<a href>` through `renderLink` from `registry/cobalt/lib/link.tsx` (D5, D19), in `--primary-ink`, underlined under the pointer with a 4px offset, with a `rounded-sm` corner so the focus outline follows the text; it takes the size and weight of the text around it, so beside a heading the caller passes `className="text-sm"`. It replaces the Button `link` variant, which drew a `<button>` for something that navigates; `wrap-break-word`, so an address or a URL as the link's text breaks inside the word only when it would run past the line, and a short label never breaks |

## Examples
A link inside a sentence, in the accent ink.

Real uses, 0 call sites (`rg -n "<TextLink\b" app registry --glob '!registry/cobalt/ui/*'`): the showcase chrome renders none yet, and the examples folder does not count.

Uses inside the registry: none. The section, card and data table examples carry the "See all" link beside a heading that the Button `link` variant used to draw.

### Example files
| File | Covers | Caption |
|---|---|---|
| `docs/system/examples/text-link/default.tsx` | default | A link inside a sentence, in the accent ink |
| Not applicable: hover is reached with the pointer on default.tsx | state:hover | The underline, 4px under the text |
| Not applicable: focus-visible is reached with the keyboard on default.tsx | state:focus-visible | The 2px outline around the text's 6px corner |
| `docs/system/examples/text-link/in-section.tsx` | composition:Section | "See all" beside a section heading, over the first few saved funds |
| `docs/system/examples/text-link/router.tsx` | composition:RenderLink | The link drawn by your router's Link through renderLink, so following it changes the page without reloading the app |
| `docs/system/examples/text-link/long-address.tsx` | state:wrapping | An address as the link's text breaks inside the word at the end of the line, so it never runs out of a narrow column |

Example: A link inside a sentence, in the accent ink (`docs/system/examples/text-link/default.tsx`)

```tsx
import { TextLink } from "@/components/cobalt/ui/text-link";

export default function Example() {
  return (
    <p className="max-w-md text-sm">
      Three items are waiting. Read the <TextLink href="#guide">saving guide</TextLink> to sort them into lists.
    </p>
  );
}
```

Example: "See all" beside a section heading, over the first few saved funds (`docs/system/examples/text-link/in-section.tsx`)

```tsx
import { Item, ItemContent, ItemDescription, ItemGroup, ItemTitle } from "@/components/cobalt/ui/item";
import { Section } from "@/components/cobalt/ui/section";
import { TextLink } from "@/components/cobalt/ui/text-link";

const saved = [
  { id: "harbour", name: "Harbour Large Cap Core", about: "Equity, $4.8B in assets" },
  { id: "calder", name: "Calder Global Equity", about: "Equity, $2.1B in assets" },
  { id: "northgate", name: "Northgate Short Duration", about: "Fixed income, $910M in assets" },
];

export default function Example() {
  return (
    <Section
      id="example-text-link"
      heading="Saved"
      className="w-full max-w-md"
      action={
        <TextLink href="#saved" className="text-sm">
          See all
        </TextLink>
      }
    >
      <ItemGroup variant="card" render={<ul aria-label="Saved funds" />}>
        {saved.map((fund) => (
          <li key={fund.id}>
            <Item render={<a href={`#${fund.id}`} />}>
              <ItemContent>
                <ItemTitle>{fund.name}</ItemTitle>
                <ItemDescription>{fund.about}</ItemDescription>
              </ItemContent>
            </Item>
          </li>
        ))}
      </ItemGroup>
    </Section>
  );
}
```

Example: The link drawn by your router's Link through renderLink, so following it changes the page without reloading the app (`docs/system/examples/text-link/router.tsx`)

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

import { TextLink } from "@/components/cobalt/ui/text-link";
import type { RenderLink } from "@/lib/cobalt/link";

const papers: Record<string, { title: string; relation: string; other: string; otherHref: string }> = {
  "/papers/flood-exposure": {
    title: "Flood exposure in coastal mortgages",
    relation: "Cited by",
    other: "Heat stress and regional output",
    otherHref: "/papers/heat-stress",
  },
  "/papers/heat-stress": {
    title: "Heat stress and regional output",
    relation: "Cites",
    other: "Flood exposure in coastal mortgages",
    otherHref: "/papers/flood-exposure",
  },
};

export default function Example() {
  // Stands in for your router: it holds the path, and its Link changes it.
  const [path, setPath] = useState("/papers/flood-exposure");
  const routerLink: RenderLink = ({ href, children, ...props }) => (
    <a
      {...props}
      href={href}
      onClick={(event) => {
        event.preventDefault();
        setPath(href);
      }}
    >
      {children}
    </a>
  );
  const paper = papers[path]!;
  return (
    <div className="flex max-w-md flex-col gap-1 text-sm">
      <p className="font-medium">{paper.title}</p>
      <p className="text-muted-foreground">
        {paper.relation}{" "}
        <TextLink href={paper.otherHref} renderLink={routerLink}>
          {paper.other}
        </TextLink>
        .
      </p>
    </div>
  );
}
```

## Variants
Not applicable: one look, the accent ink with an underline under the pointer. `TextLink` has no variant axis, and `className` is for size and placement.

## States
| State | Trigger | What the user can do | Shown by, besides color | Checked by |
|---|---|---|---|---|
| default | render | follow it, focus it | the text in `--primary-ink`; an `<a href>` in the tree | test |
| hover | pointer over, under `(hover: hover)` | follow it | the underline, with no change of size or weight | by hand |
| focus-visible | keyboard focus | follow it with Enter | the 2px outline around the 6px corner | by hand |

Example: An address as the link's text breaks inside the word at the end of the line, so it never runs out of a narrow column (`docs/system/examples/text-link/long-address.tsx`)

```tsx
import { TextLink } from "@/components/cobalt/ui/text-link";

const source = "https://example.com/data/filings/2026/q3/form-adv-part-1a-schedule-d.csv";

export default function Example() {
  return (
    <p className="max-w-xs text-sm text-muted-foreground">
      The adviser figures come from <TextLink href={source}>{source}</TextLink>, updated each quarter.
    </p>
  );
}
```

### State precedence
- Hover and focus-visible: both show. The underline sits on the text and the outline around it.

### Motion
Not applicable: no motion. The underline appears at once and the colour does not change.

## Props

<!-- Props generated from registry/cobalt/ui/text-link.tsx with TypeScript by scripts/props-table.mjs -->
| Prop | Type | Default | Purpose |
|---|---|---|---|
| `children` | `ReactNode` |  |  |
| `href` | `string` |  |  |
| `className?` | `string` |  |  |
| `renderLink?` | `RenderLink` | `defaultLink` | Swaps the plain anchor for a router link. |

`TextLink` takes `href`, `children` (the link text), `renderLink` (`RenderLink` from `registry/cobalt/lib/link.tsx`, a plain anchor by default) and `className`, merged last, for the size beside a heading or for placement. It forwards no native attributes and has no `target` or `rel`: the host's link receives `href`, `className` and `children` and adds its own, so a link that opens a new tab or another site sets `target` and `rel` in its `renderLink`.

## Usage

### When to use
- A word in a sentence leads to another page, such as "Read the saving guide".
- A heading has one link to the full list beside it, such as "See all" in a Section's `action`.

### When not to use
- The control runs an action and goes nowhere. Use Button instead.
- The link is the way back to a list. Use BackLink instead.
- The link moves between the app's sections. Use Nav instead.

### Rules
- `rule/text-link-is-an-anchor`: When text navigates, render `TextLink` with an `href`, instead of a `Button` styled as a link, because a button is announced as "button", does not open in a new tab and does not show its address. Evidence: principle platform: an anchor navigates and a button acts; principle wcag: 4.1.2 Name, role, value. Check: test `text-link.test.tsx` renders an `<a href>` and no `<button`; lint trap/link-as-button (scripts/check-system.mjs).
  - Don't: `<Button variant="ghost" onClick={() => navigate("/saved")}>See all</Button>`
  - Do: `<TextLink href="/saved" className="text-sm">See all</TextLink>`
- `rule/text-link-router-link`: When the host has a router, pass its `Link` through `renderLink` and spread the given `className`, because the default is a plain anchor that reloads the app. Evidence: person D19; single use docs/system/examples/text-link/router.tsx:44. Check: test `text-link.test.tsx` renders through a custom link and keeps the class.
  - Don't: `<TextLink href="/saved">See all</TextLink>` in an app with a router
  - Do: `<TextLink href="/saved" renderLink={({ href, className, children }) => <Link to={href} className={className}>{children}</Link>}>See all</TextLink>`

### Content
- Follows `rule/writing-link-object`.
- `rule/text-link-says-where`: When the link text is written, name where it goes, such as "See all" beside a heading or "saving guide" in a sentence, instead of "Click here" or "Learn more", because a screen reader lists links out of context and the text alone has to say the target. Evidence: principle wcag: 2.4.4 Link purpose in context. Check: lint copy/template on the link slot (scripts/copy-check.mjs); review.
  - Don't: `Read the guide <TextLink href="/guide">here</TextLink>.`
  - Do: `Read the <TextLink href="/guide">saving guide</TextLink>.`

### Anti-slop
- `rule/text-link-no-weight`: When an agent makes a text link bold or `font-medium`, pass no weight through `className`, because the accent ink already marks it and medium is for buttons and labels. Evidence: person D11; principle heuristic: aesthetic and minimalist design, one cue per link. Check: lint rule/component-override on TextLink (scripts/check-system.mjs).
  - Don't: `<TextLink href="/saved" className="font-semibold">See all</TextLink>`
  - Do: `<TextLink href="/saved" className="text-sm">See all</TextLink>`

### Limits
Not applicable: the link wraps with the text around it, and an address or a URL with no space breaks inside the word at the line's end, measured at 320px in docs/research/2026-10-16-break-ui-display.md, so it has no width limit of its own.

## Accessibility
Rests on a plain `<a href>`, or the host's link through `renderLink`.

### Keyboard
| Key | Where focus is | Effect | Focus after | Checked by |
|---|---|---|---|---|
| Tab | before the link | focuses it and shows the outline | the link | by hand |
| Enter | the link | follows it | where the router puts it | by hand |

### ARIA
| Part | Role | Accessible name from | States and properties | Announced | Checked by |
|---|---|---|---|---|---|
| root | link | its text | `href` | "link, See all" | test |

## Tokens
| Part | State | Token |
|---|---|---|
| root | all | `--primary-ink`, `--r-sm`, `--ring` |

## Related
- BackLink: the way back to a list, drawn as a grey button.
- Button: an action that goes nowhere.
- Section: the heading whose `action` slot holds the "See all" link.
- Nav: the way between sections.
- SourceLine: where a figure comes from and when it was last updated.
