Table Of Contents
A sticky React table of contents that reads h2 and h3 headings, marks the section in view with a sliding accent bar as you scroll, and smooth scrolls to a heading on click.
src/registry/ui/table-of-contents.tsx/r/table-of-contents.json
Installation#
bash
npx shadcn@latest add @minidev/table-of-contents
MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/table-of-contents.json
Usage#
tsx
import { TableOfContents } from "@/components/ui/table-of-contents"
export function Example() {
return <TableOfContents />
}
API reference#
| Prop | Type | Default |
|---|---|---|
items | TocItem[] | - |
selector | string | - |
title | string | "On this page" |
offset | number | 24 |
onActiveChange | (id: string) => void | - |
sticky | boolean | true |
className | string | - |
Dependencies#
npm
motion
Built from
No other MiniDev files
Related navigation components#
Back LinkSmall back navigation link with a left arrow icon, muted text that darkens on hover and a visible focus ring. Defaults to the label Back and accepts any href.Breadcrumb EllipsisEllipsis marker for collapsing the middle of long breadcrumb trails. Decorative and hidden from assistive tech, sized to sit between breadcrumb separators.BreadcrumbBreadcrumb navigation from an items array, with chevron separators, linked ancestors and the current page marked with aria-current. Built with React.Collapsible SidebarSidebar with a toggle button on its edge that collapses it to a narrow rail and expands it again. The button label updates for screen readers.Command ItemRow for command menus with a label, an optional keyboard shortcut in a kbd tag and an active highlight state. Use it to build custom command lists.Command PaletteCmd K style command palette in a dialog with a search field that filters commands as you type, runs the chosen action and closes. Shows an empty state.
All navigation components