---
agent:
  instructions: "Search goop.so for Goop's components, templates, design skill, docs, pricing and terms. Ask in keywords or a plain question, such as \"date picker props\" or \"is the design skill free\"; the answer is the matching page sections in Markdown, each with its address."
  endpoint: "https://goop.so/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# Contents nav

A table of contents for a long reading page (an article, a guide, a help page), each link jumping to a section, for React and Tailwind CSS. Part of Goop Pro.

Pro. Its export: `ContentsNav`.

## Try it

Scroll the guide and the nav marks the section being read; press a section (or Tab to it and press Enter) to jump there, the focus on its heading. Narrow the window: the nav becomes a bar that opens the whole list from the bottom edge, and the line under it says so.

The guide is our own. The demo routes by the address’s #, so the nav is told not to write the section there (syncHash={false}); a jump leaves the address as it was.

## When to use

- A table of contents for a long reading page (an article, a guide, a help page), each link jumping to a section.

## Installation

Paste the prompt below into your coding agent. It reads Goop's install steps, installs the part and its tokens once, then reuses this same Contents nav on every screen instead of drawing a new one: the same height, the same focus ring, the same spacing. As a Pro part, its command comes from Goop's server once you sign in, with a one-time link that lasts ten minutes.

```sh
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/meadow-contents-nav.json --yes
```

```text
Add the Goop Contents nav to this project. The install steps are at https://goop.so/docs/install.md
```

## Usage

```tsx
import { ContentsNav, ContentsNavBar, ContentsNavList } from '@/components/ui/goop/contents-nav';

function StudyGuide() {
  return (
    <div className="flex flex-col gap-6 narrow:flex-row narrow:items-start">
      <ContentsNav
        sections={[
          { id: 'planning', title: 'Planning a study' },
          { id: 'consent', title: 'Consent', sections: [{ id: 'withdraw', title: 'When someone withdraws' }] },
          { id: 'sharing', title: 'Sharing findings' },
        ]}
        className="sticky top-0 bg-background narrow:w-pane-xs narrow:shrink-0"
      >
        <ContentsNavBar className="narrow:hidden" />
        <ContentsNavList className="max-narrow:hidden" />
      </ContentsNav>
      <article className="flex flex-col gap-6 min-w-0">
        <section id="planning" className="scroll-mt-16">
          <h2 className="text-xl font-semibold">Planning a study</h2>
          <p>Write down what you want to learn before you choose who to ask.</p>
        </section>
        <section id="consent" className="scroll-mt-16">
          <h2 className="text-xl font-semibold">Consent</h2>
          <h3 id="withdraw" className="scroll-mt-16 font-semibold">When someone withdraws</h3>
          <p>Delete the recording and its notes the same day.</p>
        </section>
        <section id="sharing" className="scroll-mt-16">
          <h2 className="text-xl font-semibold">Sharing findings</h2>
          <p>One page of what you heard, with the quotes that show it.</p>
        </section>
      </article>
    </div>
  );
}
```

- Fits: record: aside (body: long).
- Also known as: TableOfContents, Toc, OnThisPage, ScrollSpy, JumpLinks.
- height, width, padding, gap, corner, background, text, motion: add no class for these.

## API reference

### Options

- `sections: readonly ContentsSection[]` — The page's sections, in the page's order: each `{ id, title, sections?
- `current?: string` — The id of the section being read, when the caller tracks it; left out, the nav tracks it itself.
- `syncHash?: boolean = true` — Whether a jump puts `#id` in the address (replacing the entry, never adding one); true unless given.
- `Defaults: aria-label = 'Contents'`

- Types: ContentsSection = { id: string; title: string; sections?: readonly ContentsSection[] }

### Parts

- `ContentsNavList` — The list of the page's sections inside a ContentsNav, the one being read marked; a second level one step in
- `ContentsNavBar` — Inside a ContentsNav on a phone; its props: contents-nav--bar.md

- data-slot values (to select a part by): contents-nav, contents-nav-bar, contents-nav-bar-title, contents-nav-bar-value, contents-nav-item, contents-nav-label, contents-nav-link, contents-nav-list

### ContentsNavBar

Inside a ContentsNav on a phone.

```tsx
import { ContentsNavBar } from '@/components/ui/goop/contents-nav';
```

### Options

- countLabel?: (place: number, total: number) => string — The bar's place words, from the section's place and the count (`3 of 7` unless given).
- open?: boolean — Whether the sheet is open, when the caller holds it; left out, the bar holds it.
- defaultOpen?: boolean = false — Whether the sheet is open at first, when the bar holds it; closed unless `true`.
- onOpenChange?: (open: boolean) => void — Called with the sheet's next open state.
- container?: HTMLElement | null — Where the sheet is portalled; the end of `<body>` when left out.
- closeLabel?: string = 'Close contents' — The spoken name of the sheet's close button.
- Also takes: onClick?: (event: MouseEvent) => void; disabled?: boolean

## Keyboard

- Tab: move to the next section's link
- Enter: jump to the section and move the focus to its heading

## Accessibility

- The native element answers the keyboard.
- hover, active, focus-visible: the browser's own (:hover, :active, :focus-visible): write nothing
- expanded: the attribute data-state=open
- open: the attribute data-state=open
- current: the attribute aria-current=location

## Motion

- The part sets its own motion: add no transition or animation of your own.

## Responsive behaviour

- Use it on a page read at length whose sections each have a heading; an app's views go in the Sidebar, a page's tabs in Tabs. Give each section an `id` and a `scroll-mt-*` as tall as any sticky bar over it. Beside the text, the list, sticky (`max-narrow:hidden`); on a phone, the bar over the text instead (`narrow:hidden`). In an app routed by the hash, `syncHash={false}`, so a jump never replaces the route.

## Notes for AI

Give your coding agent this page as text instead of screenshots: the parts, the options, the states and the keys. An agent that reads the real part builds the real part, not a lookalike.

## Related

- [Navigation menu](/themes/meadow/components/navigation-menu): A site's header menu.
- [Steps](/themes/meadow/components/steps): A strip that shows which step of a flow the user is on, for display only.
- [Tree view](/themes/meadow/components/tree-view): Nested rows a person opens and closes, to pick one (or several) of them.
- [Filter chips](/themes/meadow/components/filter-chips): The row of filters applied to a list, under its search field or filter controls.
