Anchor
A scroll-spy navigation that highlights the current section in view.
When to Use
- For long pages with multiple sections to provide in-page navigation
- As a sidebar table of contents that tracks scroll position
- For documentation pages with section anchors
Import
Examples
Vertical
The default vertical anchor navigation.
Horizontal
A horizontal anchor bar.
Nested Items
Hierarchical anchor with child sections.
API
AnchorProps
items—AnchorItem[]— Anchor link configurationdirection—"horizontal" | "vertical"— Layout direction (default:"vertical")affix—boolean— Whether to use Affix for positioning (default:true)offsetTop—number— Pixels from top when using affixtargetOffset—number— Offset from top to determine active anchorbounds—number— Bounding distance for anchor detection (default:5)replace—boolean— Replace URL hash instead of pushing (default:false)getCurrentAnchor—(activeLink: string) => string— Custom active anchor logicgetContainer—() => HTMLElement | Window— Scroll containeronChange—(currentActiveLink: string) => void— Active link change callbackonClick—(e: MouseEvent, link: { title: ReactNode; href: string }) => void— Click handler
AnchorItem
key—string— Unique identifierhref—string— Target element selectortitle—ReactNode— Display texttarget—string— Link targetchildren—AnchorItem[]— Nested itemsclassName—string— Custom CSS class