Calm motion: animations on this site only fade, with no movement
Toc
Table of contents with current heading
A list of the headings on a page, with the current one marked. Use it beside a long article or a docs page. A short page does not need one.
Basic
- Give
itemsas{ id, label, level? }. Or leaveitemsout, and the component collects the headings that matchselector(defaulth2, h3) after mount. A heading without anidis skipped. levelindents an item. In automatic mode anh3has level 1.- The current heading gets
aria-current="location". The component usesuseScrollSpy, sorootMarginworks the same way. - The observer reads its targets one time. If your headings change, remount the component with a
key. labelnames the navigation landmark. It is "On this page" by default.
Usage
ts
import { BlessToc } from "blessing-ui";API
Props
| Name | Type | Default | Description |
|---|---|---|---|
items | BlessTocItem[] | — | the headings to list. Leave out to collect them with `selector`. |
selector | string | "h2, h3" | headings to collect after mount. Each one needs an `id`. |
label | string | "On this page" | names the navigation landmark |
rootMargin | string | — | passed to the observer that marks the current heading |