# TableOfContents

> In-article table of contents for h2/h3 sections, with mobile disclosure and active-section indication.

- Status: alpha
- Group: navigation
- Page: https://www.digitaltableteur.com/design-system/components/table-of-contents
- Contract: https://www.digitaltableteur.com/contracts/v1/TableOfContents.contract.json

## When to use

Use TableOfContents in article layouts when the page exposes multiple h2/h3 sections. Pass extracted heading items and activeId from useTableOfContents; pass onItemClick when the parent owns scroll behavior.

## When not to use

- Do not use for global site navigation; use NavMenuList or SiteTree instead.
- Do not pass heading levels outside h2/h3 without updating the TOCItem contract.

## Look-alikes

- NavMenuList: Do not use for global site navigation; use NavMenuList or SiteTree instead.
- SiteTree: Do not use for global site navigation; use NavMenuList or SiteTree instead.

## Props

| Prop | Type | Default | Description | Required |
| --- | --- | --- | --- | --- |
| `items` | `TOCItem[]` | none | Array of headings to display. | Yes |
| `activeId` | `string \| null` | none | Currently active heading ID. | No |
| `sticky` | `boolean` | `false` | Make TOC sticky on scroll. | No |
| `onItemClick` | `(id: string) => void` | none | Callback when item is clicked. | No |
| `className` | `string` | none | Custom className. | No |

## Variants

No variant dimensions and no props with a fixed set of values.

## Invalid combinations

The contract records no invalid combinations.

## Keyboard

| Key | Behaviour |
| --- | --- |
| Tab | Reaches the disclosure trigger and each heading button. |
| Enter / Space | Toggles the mobile disclosure and activates heading buttons. |

## Rules

Every item under When not to use is a MUST NOT. MUST and SHOULD follow RFC 2119.

| Level | Rule | How it is checked |
| --- | --- | --- |
| MUST | ARIA: Nav landmark with a localized aria-label. | Not yet verified: no evidence record. WCAG 4.1.2. |
| MUST | ARIA: Mobile trigger exposes aria-expanded and aria-controls. | Not yet verified: no evidence record. WCAG 4.1.2. |
| MUST | ARIA: Active heading button exposes aria-current='location'. | Not yet verified: no evidence record. WCAG 4.1.2. |
| MUST | Required stories produce no axe violations at the configured severity. | Automated by `npm run test:stories:matrix:ci`. WCAG 2.5.8. |
| MUST | The accessibility tree (role, name, state) matches the committed snapshot for every required story. | Automated by `npm run test:stories:matrix:ci`. WCAG 1.3.1, 4.1.2. |
| MUST | The component remains legible and operable under a real browser forced-colors: active pass. | Automated by `npm run test:stories:hc`. |
| MUST | Every documented keyboard interaction works as specified. | Not yet verified: no evidence record. WCAG 2.1.1, 2.1.2. |

## Install and import

- In-repo only. TableOfContents is not exported from `@digitaltableteur/react`, so there is no public import path.
- Alpha components are internal and never exported.

## Links

- Machine-readable contract (Design System Contract 1.0): https://www.digitaltableteur.com/contracts/v1/TableOfContents.contract.json
- Markdown version of this page: https://www.digitaltableteur.com/design-system/components/table-of-contents.md
- Component index as JSON: https://www.digitaltableteur.com/design-system/components.json
- All components: https://www.digitaltableteur.com/design-system/components
- Source: The implementation lives in a private repository. This page, its Markdown twin and the contract are generated from it at build time and are the public source of truth.
