목차
제목으로 이동하고 현재 보이는 섹션을 추적합니다.
사용법
제목 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>
</>