Table of Contents
Link to headings and track the visible section.
Usage
Supply heading IDs and an optional content ID or controlled active ID. Use native fragment links or handle navigation in the consumer.
Accessibility
Preserve section IDs, indicate the current location and allow mobile users to return focus to the disclosure or heading.
| Property | Type | Default |
|---|---|---|
| headings | readonly TocHeading[] | Required |
| label | string | Required |
| contentId | string | Document body |
| offset | number | 0 |
| activeId | string | null | Observed |
| mobileLabel | string | None |
| onNavigate | function | Native anchor |
<>
<TableOfContents label="On this page" mobileLabel="Browse sections"
contentId="om-toc-demo-article"
headings={[
{ id: 'om-toc-demo-setup', label: 'Installation', level: 2 },
{ id: 'om-toc-demo-usage', label: 'Usage guide', level: 3 }
]}
onNavigate={(heading, event) => {
event.preventDefault();
document.getElementById(heading.id)?.scrollIntoView({ block: 'start' });
}}
/>
<article id="om-toc-demo-article">
<h3 id="om-toc-demo-setup" tabIndex={-1}>Installation</h3>
<p>Install the package.</p>
<h3 id="om-toc-demo-usage" tabIndex={-1}>Usage guide</h3>
<p>Learn how to use the library.</p>
</article>
</>