Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Page pieces (landing pages, portfolios, docs)

TableOfContents

In-page jump links that highlight the section in view (scroll spy), like the "On this page" list in docs.

import { TableOfContents } from "@stylhero/ui";

Example

Code
import { TableOfContents } from "@stylhero/ui";

function TableOfContentsExample() {
  return <TableOfContents label="On this page" items={[{ id: "example", label: "Example" }, { id: "props", label: "Props" }, { id: "keyboard", label: "Keyboard" }]} />;
}

Props

PropTypeDefaultDescription
items required TocItem[] - Sections on the page, by element id.
label string "On this page"

Also takes the HTML attributes of its root element (id, style, data-*, aria-*, event handlers…).

Types

type TocItem = { id: string; label: ReactNode };

Accessibility

  • A labelled <nav> that marks the section in view with aria-current.

Generated from src/components/TableOfContents.tsx. Something wrong or missing? Open an issue.