Client component

Table of Contents

"On this page" navigation with scroll-spy: the entry whose heading is currently on screen is highlighted, driven by IntersectionObserver — no scroll handler. The entries are plain anchor links, so navigation works before hydration and with JavaScript disabled; only the highlight is the enhancement.

Introduction

Scroll this pane — the entry for the section under the header highlights on the right. The links are plain anchors, so they work before hydration too.

Installation

Scroll this pane — the entry for the section under the header highlights on the right. The links are plain anchors, so they work before hydration too.

Theming

Scroll this pane — the entry for the section under the header highlights on the right. The links are plain anchors, so they work before hydration too.

Tokens

Scroll this pane — the entry for the section under the header highlights on the right. The links are plain anchors, so they work before hydration too.

FAQ

Scroll this pane — the entry for the section under the header highlights on the right. The links are plain anchors, so they work before hydration too.

Import#

import { TableOfContents } from "astralis-ui";

Usage#

Point items at heading ids that exist in the page:

<TableOfContents
  items={[
    { id: "installation", title: "Installation" },
    { id: "theming", title: "Theming", depth: 1 },
    { id: "api", title: "API" },
  ]}
/>

Props#

Extends nav props:

PropTypeDefaultDescription
items{ id: string; title: string; depth?: number }[]—The entries. Each id must match a heading's id on the page; depth indents it. Required.
labelstring"On this page"Accessible name of the nav, also shown as a title above the list.
showLabelbooleantrueShows the label above the list. Hidden, it still names the nav.
offsetnumber80Height of a sticky header, in pixels, so the entry highlights when its heading clears it.

Keyboard#

The entries are plain links: Tab moves through them and Enter jumps to the heading. The highlight follows the scroll position, not focus.