Skip to content

Layout

Toc

Table of contents from an items list, Toc.Item links, or scanned headings, with active-heading highlighting.

import { Toc } from '@var-ui/react';

Toc

In-page table of contents. Pass a flat items list, compose manual Toc.Items, or enable auto to scan headings in a content root. Priority is items, then children, then auto. Entries render React Aria Link, so href honours RouterProvider for client-side routing.

Examples

Default

A flat list of section anchors with one selected item.

Demo.tsxTSX
import { Toc } from '@var-ui/react';

<Toc title="On this page">
  <Toc.Item label="Examples" href="#examples" selected />
  <Toc.Item label="Props" href="#props" />
</Toc>

Nested items

Mark subsection links with nested (matches auto mode’s h3 indent).

Demo.tsxTSX
import { Toc } from '@var-ui/react';

<Toc title="On this page">
  <Toc.Item label="Examples" href="#examples" selected />
  <Toc.Item label="Default" href="#default" nested />
  <Toc.Item label="Nested items" href="#nested" nested />
  <Toc.Item label="Props" href="#props" />
  <Toc.Item label="Accessibility" href="#accessibility" />
</Toc>

Items list

Pass items ({ id, text, level }; level: 3 nests) and a controlled activeId. activeId overrides the scroll spy for items and auto lists. Available in React and Astro.

Demo.tsxTSX
import { Toc } from '@var-ui/react';

<Toc
  activeId="examples"
  items={[
    { id: 'intro', text: 'Intro', level: 2 },
    { id: 'examples', text: 'Examples', level: 2 },
    { id: 'default', text: 'Default', level: 3 },
    { id: 'props', text: 'Props', level: 2 },
  ]}
/>

Props

Accessibility

The root is a nav landmark. Selected items set aria-current="location". Prefer stable heading ids so href="#…" targets resolve.