npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-contents-nav.json --yesContents nav
ProA 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.
import { ContentsNav, ContentsNavList, ContentsNavBar } from '@/components/ui/goop/contents-nav';
<div className="flex flex-col gap-6 narrow:flex-row narrow:items-start">
<ContentsNav
sections={[
{ id: "overview", title: "Overview" },
{ id: "the-route", title: "The route", sections: [{ id: "the-climb", title: "The climb" }] },
{ id: "what-to-bring", title: "What to bring" },
]}
className="sticky top-0 z-sticky 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="overview" className="scroll-mt-16">
<h2 className="text-xl font-semibold">Overview</h2>
<p>A day's walk over the ridge and back by the lake.</p>
</section>
<section id="the-route" className="scroll-mt-16">
<h2 className="text-xl font-semibold">The route</h2>
<h3 id="the-climb" className="scroll-mt-16 font-semibold">The climb</h3>
<p>Two hours of switchbacks up to the pass.</p>
</section>
<section id="what-to-bring" className="scroll-mt-16">
<h2 className="text-xl font-semibold">What to bring</h2>
<p>Water, a layer for the wind and a map.</p>
</section>
</article>
</div>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.
npx shadcn@4.23.1 add https://registry.goop.so/g/<link>/trail-contents-nav.json --yesAdd the Goop Contents nav to this project. The install steps are at https://goop.so/docs/install.mdUsage
import { ContentsNav, ContentsNavList, ContentsNavBar } from '@/components/ui/goop/contents-nav';
<div className="flex flex-col gap-6 narrow:flex-row narrow:items-start">
<ContentsNav
sections={[
{ id: "overview", title: "Overview" },
{ id: "the-route", title: "The route", sections: [{ id: "the-climb", title: "The climb" }] },
{ id: "what-to-bring", title: "What to bring" },
]}
className="sticky top-0 z-sticky 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="overview" className="scroll-mt-16">
<h2 className="text-xl font-semibold">Overview</h2>
<p>A day's walk over the ridge and back by the lake.</p>
</section>
<section id="the-route" className="scroll-mt-16">
<h2 className="text-xl font-semibold">The route</h2>
<h3 id="the-climb" className="scroll-mt-16 font-semibold">The climb</h3>
<p>Two hours of switchbacks up to the pass.</p>
</section>
<section id="what-to-bring" className="scroll-mt-16">
<h2 className="text-xl font-semibold">What to bring</h2>
<p>Water, a layer for the wind and a map.</p>
</section>
</article>
</div>- Fits: record: aside (body: long).
- Also known as: TableOfContents, Toc, OnThisPage, ScrollSpy, JumpLinks.
- height, width, padding, gap, corner, border, background, text, motion: add no class for these.
API reference
| Option | Type | What it does |
|---|---|---|
| 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[] }
| Part | What it is |
|---|---|
| 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; 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 |
- 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
Keyboard
| Key | What it does |
|---|---|
| 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
Its states are drawn from attributes and props, so assistive technology and your agent read the same thing:
| State | Drawn by |
|---|---|
| current | the attribute aria-current=location |
Motion
- The part sets its own motion: add no transition or animation of your own.
- How the theme moves, and how to move your own parts the same way: Motion.
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
idand ascroll-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.