Table Of Contents
Scrollspy on-this-page nav with an animated active indicator.
Import
import { TableOfContents } from "@cronus-ui/ui";
npx cronus-ui add table-of-contents
Examples
.cronus
The same component declared in Cronus. Emitted at build time from the audit fixtures — the kernel renders it as HTML with no React.
default.cronus
app "audit-fixtures" {
port 5176
}
style {
preset aurora
theme dark
}
component TableOfContentsDefault layout:inline style:table-of-contents {
aria-label:"On this page"
label "On this page"
text "Overview"
text "Usage"
}
page "/audit/table-of-contents/default" type:custom {
use TableOfContentsDefault
}
API Reference
Generated from the component's exported types.
TableOfContentsProps
Extends Omit<HTMLAttributes<HTMLElement>, "children">
| Prop | Type | Default | Description |
|---|---|---|---|
items | TableOfContentsItem[] | — | The entries to render, in document order. When omitted, headings are auto-discovered from the DOM via . |
selector | string | DEFAULT_SELECTOR | CSS selector used to auto-discover headings when is omitted. Only elements with an `id` participate; depth is derived from the heading level (the shallowest level found becomes depth 0). Defaults to `"h2, h3"`. |
containerId | string | — | `id` of the element that scopes heading discovery. When that element is itself a scroll container (`overflow-y: auto | scroll`), it also becomes the scrollspy root and the target of click-to-scroll — otherwise the window scrolls. Defaults to the whole document. |
offset | number | 0 | Pixels between the top of the scroll root and the activation line — match your sticky-header height. Also subtracted when scrolling to a section on click. Defaults to `0`. |
className | string | — | Additional class names merged onto the root. |
id | string | — | DOM id of the root element. |