目次
見出しへリンクし、表示中のセクションを追跡します。
使い方
見出し ID と任意の本文 ID または制御されたアクティブ ID を渡します。ネイティブフラグメントリンクを使うか、利用側で移動を扱います。
アクセシビリティ
セクション ID を保持し、現在位置を示し、モバイル利用者が展開ボタンまたは見出しにフォーカスを戻せるようにします。
| プロパティ | 型 | 既定値 |
|---|---|---|
| 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>
</>