Skip to content
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 items as { id, label, level? }. Or leave items out, and the component collects the headings that match selector (default h2, h3) after mount. A heading without an id is skipped.
  • level indents an item. In automatic mode an h3 has level 1.
  • The current heading gets aria-current="location". The component uses useScrollSpy, so rootMargin works the same way.
  • The observer reads its targets one time. If your headings change, remount the component with a key.
  • label names the navigation landmark. It is "On this page" by default.

Usage ​

ts
import { BlessToc } from "blessing-ui";

API ​

Props

NameTypeDefaultDescription
itemsBlessTocItem[]—the headings to list. Leave out to collect them with `selector`.
selectorstring"h2, h3"headings to collect after mount. Each one needs an `id`.
labelstring"On this page"names the navigation landmark
rootMarginstring—passed to the observer that marks the current heading

Released under the MIT License. Character names and artwork belong to their owners.