> For AI agents: the complete documentation index is available at https://wallarm.github.io/design-system/llms.txt, the full documentation bundle is available at https://wallarm.github.io/design-system/llms-full.txt.

# TableOfContents

Lists the sections of one long page, such as a report, shows which one is being read and jumps to a section on click — reach for `Tabs` or `SegmentedTabs` when only one section shows at a time, and `Stepper` when the sections are steps of a flow. It never tracks scrolling itself: the page passes the active `value`, usually from the `useScrollSpy` hook, and the corner button switches to the Minimized view of dashes, whose popover opens on hover or tap.

[Source](https://github.com/wallarm/design-system/tree/main/packages/design-system/src/components/TableOfContents) · [Storybook](https://wallarm.github.io/design-system/storybook/?path=/docs/navigation-tableofcontents--overview)

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const Basic = () => {
  const [value, setValue] = useState('findings');
  return (
    <TableOfContents value={value} onValueChange={setValue} data-testid='toc'>
      {SECTIONS.map(section => (
        <TableOfContentsItem key={section.id} value={section.id}>
          {section.label}
        </TableOfContentsItem>
      ))}
    </TableOfContents>
  );
};
```

## Usage

```tsx
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';
```

## Examples

### Numbered

The page passes each `number` itself — nothing is counted — and it stays on the first line.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const Numbered = () => {
  const [value, setValue] = useState('findings');
  return (
    <TableOfContents value={value} onValueChange={setValue} data-testid='toc'>
      <TableOfContentsItem value='tldr'>TL;DR</TableOfContentsItem>
      <TableOfContentsItem value='findings' number='1'>
        Findings
      </TableOfContentsItem>
      <TableOfContentsItem value='impact' number='2'>
        Impact
      </TableOfContentsItem>
      <TableOfContentsItem value='remediation' number='3'>
        Remediation
      </TableOfContentsItem>
    </TableOfContents>
  );
};
```

### Levels

Two levels at most: `level={2}` indents a subsection under its parent on the same rail.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const Levels = () => {
  const [value, setValue] = useState('critical');
  return (
    <TableOfContents value={value} onValueChange={setValue} data-testid='toc'>
      <TableOfContentsItem value='findings' number='1'>
        Findings
      </TableOfContentsItem>
      <TableOfContentsItem value='critical' number='1.1' level={2}>
        Critical
      </TableOfContentsItem>
      <TableOfContentsItem value='high' number='1.2' level={2}>
        High
      </TableOfContentsItem>
      <TableOfContentsItem value='impact' number='2'>
        Impact
      </TableOfContentsItem>
      <TableOfContentsItem value='scope' number='2.1' level={2}>
        Scope
      </TableOfContentsItem>
    </TableOfContents>
  );
};
```

### Minimized

A dash per section, longest for the active one; hover or tap the dashes to read the rows in a popover.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const Minimized = () => {
  const [value, setValue] = useState('findings');
  return (
    <TableOfContents
      defaultView='minimized'
      value={value}
      onValueChange={setValue}
      data-testid='toc'
    >
      <TableOfContentsItem value='tldr'>TL;DR</TableOfContentsItem>
      <TableOfContentsItem value='findings' number='1'>
        Findings
      </TableOfContentsItem>
      <TableOfContentsItem value='critical' number='1.1' level={2}>
        Critical
      </TableOfContentsItem>
      <TableOfContentsItem value='impact' number='2'>
        Impact
      </TableOfContentsItem>
    </TableOfContents>
  );
};
```

### Long labels

Labels wrap to two lines, then end in an ellipsis; the rail grows with the row.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const LongLabels = () => {
  const [value, setValue] = useState('short');
  return (
    <TableOfContents value={value} onValueChange={setValue} data-testid='toc'>
      <TableOfContentsItem value='short'>Summary</TableOfContentsItem>
      <TableOfContentsItem value='two-lines' number='1'>
        Attacks blocked by the filtering node
      </TableOfContentsItem>
      <TableOfContentsItem value='clamped' number='1.1' level={2}>
        Requests from the top ten source addresses that hit the API in the last thirty days
      </TableOfContentsItem>
    </TableOfContents>
  );
};
```

### Long list

The list scrolls inside the height its parent gives it, while the header stays put.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';

export const LongList = () => {
  const [value, setValue] = useState('section-1');
  return (
    <div className='flex h-240'>
      <TableOfContents value={value} onValueChange={setValue} data-testid='toc'>
        {LONG_LIST.map(section => (
          <TableOfContentsItem key={section.id} value={section.id}>
            {section.label}
          </TableOfContentsItem>
        ))}
      </TableOfContents>
    </div>
  );
};
```

### With scroll spy

The usual wiring: `useScrollSpy` reads the scrolling container and feeds `value` and `scrollTo` back in.

```tsx
import { useState } from 'react';
import { TableOfContents, TableOfContentsItem } from '@wallarm-org/design-system/TableOfContents';
import { Text } from '@wallarm-org/design-system/Text';
import { useScrollSpy } from '../../hooks';

export const WithScrollSpy = () => {
  const [root, setRoot] = useState<HTMLDivElement | null>(null);
  const { activeId, scrollTo } = useScrollSpy({ ids: SECTION_IDS, root, offset: 16 });
  return (
    <div className='flex h-320 gap-24'>
      <TableOfContents value={activeId} onValueChange={scrollTo} data-testid='toc'>
        {SECTIONS.map(section => (
          <TableOfContentsItem key={section.id} value={section.id}>
            {section.label}
          </TableOfContentsItem>
        ))}
      </TableOfContents>
      <div
        ref={setRoot}
        data-testid='toc-content'
        className='flex-1 overflow-y-auto rounded-8 border border-border-primary p-16'
      >
        {SECTIONS.map(section => (
          <section
            key={section.id}
            id={section.id}
            data-testid={`toc-section-${section.id}`}
            className='min-h-200 pb-16'
          >
            <Text size='lg' weight='medium'>
              {section.label}
            </Text>
            <Text color='secondary'>Body of the {section.label} section.</Text>
          </section>
        ))}
      </div>
    </div>
  );
};
```

### With segmented tabs

The same hook drives any control that takes a `value` — here `SegmentedTabs` across the top of the page.

```tsx
import { useState } from 'react';
import { SegmentedTabs, SegmentedTabsList, SegmentedTabsTrigger } from '@wallarm-org/design-system/SegmentedTabs';
import { Text } from '@wallarm-org/design-system/Text';
import { useScrollSpy } from '../../hooks';

export const WithSegmentedTabs = () => {
  const [root, setRoot] = useState<HTMLDivElement | null>(null);
  const { activeId, scrollTo } = useScrollSpy({ ids: SECTION_IDS, root, offset: 16 });
  return (
    <div className='flex h-320 flex-col gap-12'>
      <SegmentedTabs value={activeId} onChange={scrollTo} data-testid='toc-tabs'>
        <SegmentedTabsList>
          {SECTIONS.map(section => (
            <SegmentedTabsTrigger key={section.id} value={section.id}>
              {section.label}
            </SegmentedTabsTrigger>
          ))}
        </SegmentedTabsList>
      </SegmentedTabs>
      <div
        ref={setRoot}
        data-testid='toc-content'
        className='flex-1 overflow-y-auto rounded-8 border border-border-primary p-16'
      >
        {SECTIONS.map(section => (
          <section
            key={section.id}
            id={section.id}
            data-testid={`toc-section-${section.id}`}
            className='min-h-200 pb-16'
          >
            <Text size='lg' weight='medium'>
              {section.label}
            </Text>
            <Text color='secondary'>Body of the {section.label} section.</Text>
          </section>
        ))}
      </div>
    </div>
  );
};
```

## Props

| Prop           | Type                                                 | Default        | Description                                                                                                              |
| -------------- | ---------------------------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------ |
| value          | `string \| undefined`                                |                | The active item's value. Controlled only — the page owns the active section.                                             |
| onValueChange  | `((value: string) => void) \| undefined`             |                | Called with the item's value on a plain click on an in-page item.                                                        |
| view           | `TableOfContentsView \| undefined`                   | `defaultView`  | Controlled view.                                                                                                         |
| defaultView    | `TableOfContentsView \| undefined`                   | `full`         | Uncontrolled initial view.                                                                                               |
| onViewChange   | `((view: TableOfContentsView) => void) \| undefined` |                |                                                                                                                          |
| title          | `string \| undefined`                                | `On this page` | Header label in the Full view; the accessible name of the nav, the toggle and the popover unless `aria-label` is passed. |
| defaultChecked | `boolean \| undefined`                               |                |                                                                                                                          |
| defaultValue   | `string \| number \| readonly string[] \| undefined` |                |                                                                                                                          |
| autoFocus      | `boolean \| undefined`                               |                |                                                                                                                          |
| id             | `string \| undefined`                                |                |                                                                                                                          |
| tabIndex       | `number \| undefined`                                |                |                                                                                                                          |
| rel            | `string \| undefined`                                |                |                                                                                                                          |
| data-testid    | `string \| undefined`                                |                |                                                                                                                          |

### TableOfContentsItem

| Prop           | Type                                                 | Default | Description                                        |
| -------------- | ---------------------------------------------------- | ------- | -------------------------------------------------- |
| value \*       | `string`                                             |         | Section id. `href` defaults to `#${value}`.        |
| level          | `1 \| 2 \| undefined`                                | `1`     | Nesting level; level 2 is indented.                |
| number         | `ReactNode`                                          |         | Section number shown before the label, e.g. `1.1`. |
| download       | `any`                                                |         |                                                    |
| href           | `string \| undefined`                                |         |                                                    |
| hrefLang       | `string \| undefined`                                |         |                                                    |
| target         | `HTMLAttributeAnchorTarget \| undefined`             |         |                                                    |
| type           | `string \| undefined`                                |         |                                                    |
| defaultChecked | `boolean \| undefined`                               |         |                                                    |
| defaultValue   | `string \| number \| readonly string[] \| undefined` |         |                                                    |
| autoFocus      | `boolean \| undefined`                               |         |                                                    |
| id             | `string \| undefined`                                |         |                                                    |
| tabIndex       | `number \| undefined`                                |         |                                                    |
| title          | `string \| undefined`                                |         |                                                    |
| rel            | `string \| undefined`                                |         |                                                    |
| onChange       | `ChangeEventHandler<T, Element> \| undefined`        |         |                                                    |
| data-testid    | `string \| undefined`                                |         |                                                    |

## Explorer

