Basic Usage
app/docs/[...slug]/page.tsx
Data Structure
TOC Provider
Set up TOC context:Core Hooks
useActiveAnchor
Get the currently active heading:useActiveAnchors
Get all visible anchors (whensingle={false}):
useTOCItems
Access TOC items from context:TOC Components
Default TOC
- Shows “No headings” message when empty
- Applies depth-based indentation
- Highlights active headings
- Includes animated thumb indicator
TOC Item
TOC Scroll Area
Scrollable container with mask:- Auto-scrolls to active item
- Gradient mask at top/bottom
- Thin scrollbar (hidden)
- Min height constraint
TOC Thumb
Animated position indicator:- Tracks active heading position
- Smooth height/position transitions
- Hides when no active items
- Uses CSS custom properties
--fd-topand--fd-height
Scroll Provider
Enable auto-scroll to active items:Active Detection
Heading detection usesIntersectionObserver:
- Selects topmost visible heading by default
- Selects last item when scrolled to bottom
- Falls back to nearest heading when none visible
- Supports multiple active items (when
single={false})
Styling
Depth Indentation
Custom Thumb
Empty State
Handle pages without headings:Advanced Example
Full custom TOC implementation:Integration with MDX
TOC is automatically generated from MDX headings:Best Practices
- Single Mode: Use
single={true}for cleaner highlighting on long pages - Depth Limits: Only show h2-h4 headings for better readability
- Scroll Area: Always wrap TOC in scroll area for long lists
- Empty State: Show helpful message when no headings exist
- Mobile: Hide TOC on mobile or show in collapsible section
- Sticky Position: Make TOC sticky for easy access while scrolling
- Smooth Scroll: Browser handles smooth scrolling automatically with anchor links