Skip to content
synccn

Table of Contents

New

Section links that follow your scroll position.

Introduction

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

Installation

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

Vite

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

Next.js

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

Theming

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

FAQ

Scroll this panel and watch the contents on the right follow along. Clicking an item scrolls to its section.

Installation

$ pnpm dlx shadcn@latest add @synccn/table-of-contents

First time in this project? Connect synccn with one command.

Usage

import { TableOfContents } from "@/components/ui/nav-extras";<TableOfContents items={sections} />

API reference

Generated from the component's TypeScript types, so it always matches the code.

TableOfContents

Table of contents that highlights the section in view (scrollspy). items: [{ id, label, level? }]; root: optional scroll container ref.

  • itemsrequired
    { id: string; label: string; level?: 1 | 2 }[]

    Sections, matched to elements by id.

  • root
    React.RefObject<HTMLElement | null>

    Scroll container to watch. Defaults to the page.

  • className
    string

    Extra classes for the root element.

Dependencies

Read from the component's imports when the site builds. The CLI installs all of these for you.

Helpers

  • lib/utilscn (merges class names)
  • lib/hooksuseClickOutside (closes on an outside click), useEscape (closes on Escape)

npm packages

Accessibility

From the source

Read from this component's code when the site builds, so it can't drift.

  • ARIA attributes: aria-current, aria-expanded, aria-hidden, aria-label
  • Closes with Escape
  • Closes when you click or tap outside