# Table of Content

Use `ui-table-of-content` in documentation pages, long settings panels, knowledge content, or any reading surface where users benefit from quick in-page navigation. The real quality of the result depends more on content structure than on visual styling.

## Import
```ts
import { TableOfContentComponent } from 'ui';
```

## Basic in-page navigation
```ts
import { Component } from '@angular/core';
import { TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-basic-demo',
  standalone: true,
  imports: [TableOfContentComponent],
  template: `
    <div
      style="display:flex;flex-wrap:wrap;gap:1rem;align-items:flex-start;width:100%;max-width:58rem"
    >
      <div
        style="flex:0 0 16rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <ui-table-of-content containerSelector=".toc-basic-content" [minLevel]="2" [maxLevel]="3" />
      </div>

      <div
        class="toc-basic-content"
        style="flex:1 1 24rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <h2 id="toc-basic-overview">Overview</h2>
        <p style="margin:0 0 1rem">
          Table of content scans headings inside the target container and builds in-page navigation
          automatically.
        </p>
        <h3 id="toc-basic-import">Import</h3>
        <p style="margin:0 0 1rem">Point the component at the content area you want to index.</p>
        <h2 id="toc-basic-usage">Usage</h2>
        <p style="margin:0 0 1rem">
          Use semantic heading order so nested sections remain understandable.
        </p>
        <h3 id="toc-basic-structure">Structure</h3>
        <p style="margin:0">
          Keep heading depth intentional instead of generating long noisy trees.
        </p>
      </div>
    </div>
  `,
})
export class TableOfContentBasicDemoComponent {}
```

## Heading level filtering
```ts
import { Component } from '@angular/core';
import { TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-levels-demo',
  standalone: true,
  imports: [TableOfContentComponent],
  template: `
    <div
      style="display:flex;flex-wrap:wrap;gap:1rem;align-items:flex-start;width:100%;max-width:60rem"
    >
      <div
        style="flex:1 1 18rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <p
          style="margin:0 0 0.75rem;font-size:0.875rem;font-weight:600;color:var(--color-neutral-foreground2-rest)"
        >
          H2-H3 navigation
        </p>
        <ui-table-of-content
          containerSelector=".toc-levels-content"
          [minLevel]="2"
          [maxLevel]="3"
        />
      </div>

      <div
        style="flex:1 1 18rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <p
          style="margin:0 0 0.75rem;font-size:0.875rem;font-weight:600;color:var(--color-neutral-foreground2-rest)"
        >
          H3-H4 navigation
        </p>
        <ui-table-of-content
          containerSelector=".toc-levels-content"
          [minLevel]="3"
          [maxLevel]="4"
          appearance="outline"
        />
      </div>

      <div
        class="toc-levels-content"
        style="flex:1 1 100%;padding:1rem;border:1px dashed var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background2-rest)"
      >
        <h2 id="toc-levels-getting-started">Getting started</h2>
        <p style="margin:0 0 1rem">Top-level docs section.</p>
        <h3 id="toc-levels-installation">Installation</h3>
        <p style="margin:0 0 1rem">Install and wire the target container.</p>
        <h4 id="toc-levels-cli">CLI setup</h4>
        <p style="margin:0 0 1rem">Project scaffolding details.</p>
        <h3 id="toc-levels-configuration">Configuration</h3>
        <p style="margin:0 0 1rem">Heading range and sticky offset live here.</p>
        <h4 id="toc-levels-routing">Routing</h4>
        <p style="margin:0">Deep topic for nested content.</p>
      </div>
    </div>
  `,
})
export class TableOfContentLevelsDemoComponent {}
```

## Sticky behavior and offset
```ts
import { Component } from '@angular/core';
import { TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-sticky-demo',
  standalone: true,
  imports: [TableOfContentComponent],
  template: `
    <div
      style="display:grid;grid-template-columns:minmax(14rem,16rem) minmax(0,1fr);gap:1rem;width:100%;max-width:62rem;height:28rem;overflow:auto;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:linear-gradient(180deg,var(--color-neutral-background-rest),var(--color-neutral-background2-rest))"
    >
      <ui-table-of-content
        containerSelector=".toc-sticky-content"
        [sticky]="true"
        [offsetTop]="12"
        [minLevel]="2"
        [maxLevel]="3"
      />

      <div
        class="toc-sticky-content"
        style="display:flex;flex-direction:column;gap:1rem;min-width:0;padding-right:0.5rem"
      >
        <h2 id="toc-sticky-intro">Introduction</h2>
        <p style="margin:0">
          Sticky mode keeps the current section list visible while the reading panel scrolls.
        </p>
        <h2 id="toc-sticky-layout">Layout</h2>
        <p style="margin:0">
          Use offset when the page has a fixed app header or secondary sticky shell.
        </p>
        <h3 id="toc-sticky-side-panels">Side panels</h3>
        <p style="margin:0">TOC often lives beside docs or knowledge content.</p>
        <h2 id="toc-sticky-writing">Writing guidance</h2>
        <p style="margin:0">
          The heading structure should stay cleaner than the TOC configuration itself.
        </p>
        <h3 id="toc-sticky-long-form">Long-form sections</h3>
        <p style="margin:0">
          This container is intentionally taller to make sticky behavior obvious.
        </p>
        <div
          style="height:14rem;border:1px dashed var(--color-neutral-stroke-rest);border-radius:0.875rem;background:var(--color-neutral-background-rest)"
        ></div>
        <h2 id="toc-sticky-summary">Summary</h2>
        <p style="margin:0">A good TOC reduces scanning cost without overwhelming the page.</p>
      </div>
    </div>
  `,
})
export class TableOfContentStickyDemoComponent {}
```

## Appearance and indicator style
```ts
import { Component } from '@angular/core';
import { TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-appearance-demo',
  standalone: true,
  imports: [TableOfContentComponent],
  template: `
    <div
      style="display:grid;grid-template-columns:repeat(auto-fit,minmax(15rem,1fr));gap:1rem;width:100%;max-width:58rem"
    >
      <div
        style="padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <p
          style="margin:0 0 0.75rem;font-size:0.875rem;font-weight:600;color:var(--color-neutral-foreground2-rest)"
        >
          Subtle
        </p>
        <ui-table-of-content containerSelector=".toc-appearance-content" appearance="subtle" />
      </div>

      <div
        style="padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <p
          style="margin:0 0 0.75rem;font-size:0.875rem;font-weight:600;color:var(--color-neutral-foreground2-rest)"
        >
          Outline
        </p>
        <ui-table-of-content containerSelector=".toc-appearance-content" appearance="outline" />
      </div>

      <div
        style="padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <p
          style="margin:0 0 0.75rem;font-size:0.875rem;font-weight:600;color:var(--color-neutral-foreground2-rest)"
        >
          Filled
        </p>
        <ui-table-of-content
          containerSelector=".toc-appearance-content"
          appearance="filled"
          indicatorPosition="horizontal"
        />
      </div>

      <div
        class="toc-appearance-content"
        style="grid-column:1 / -1;padding:1rem;border:1px dashed var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background2-rest)"
      >
        <h2 id="toc-appearance-overview">Overview</h2>
        <p style="margin:0 0 1rem">
          Appearance changes how strong the side navigation feels against the surrounding shell.
        </p>
        <h3 id="toc-appearance-spacing">Spacing</h3>
        <p style="margin:0 0 1rem">Choose the calmer style for long documentation panes.</p>
        <h2 id="toc-appearance-accessibility">Accessibility</h2>
        <p style="margin:0">
          Indicators should remain visible without overpowering the reading surface.
        </p>
      </div>
    </div>
  `,
})
export class TableOfContentAppearanceDemoComponent {}
```

## Custom heading selectors
```ts
import { Component } from '@angular/core';
import { TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-heading-selector-demo',
  standalone: true,
  imports: [TableOfContentComponent],
  template: `
    <div
      style="display:flex;flex-wrap:wrap;gap:1rem;align-items:flex-start;width:100%;max-width:60rem"
    >
      <div
        style="flex:0 0 16rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <ui-table-of-content
          containerSelector=".toc-heading-selector-content"
          headingSelector="[data-toc]"
          [minLevel]="1"
          [maxLevel]="6"
        />
      </div>

      <div
        class="toc-heading-selector-content"
        style="flex:1 1 26rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
      >
        <div
          data-toc
          id="toc-selector-hero"
          style="margin:0 0 0.75rem;font-size:1.125rem;font-weight:700"
        >
          Hero section
        </div>
        <p style="margin:0 0 1rem">
          You can build a TOC from custom markers, not only semantic heading tags.
        </p>
        <div
          data-toc
          id="toc-selector-usage"
          style="margin:0 0 0.75rem;font-size:1rem;font-weight:700"
        >
          Usage notes
        </div>
        <p style="margin:0 0 1rem">
          This helps when content is rendered from CMS blocks or custom prose components.
        </p>
        <div
          data-toc
          id="toc-selector-api"
          style="margin:0 0 0.75rem;font-size:1rem;font-weight:700"
        >
          API notes
        </div>
        <p style="margin:0">
          Use this selectively. Normal semantic headings are still the cleaner default.
        </p>
      </div>
    </div>
  `,
})
export class TableOfContentHeadingSelectorDemoComponent {}
```

## Documentation layout composition
```ts
import { Component } from '@angular/core';
import { DividerComponent, MessageBarComponent, TableOfContentComponent } from 'ui';

@Component({
  selector: 'app-table-of-content-doc-layout-demo',
  standalone: true,
  imports: [DividerComponent, MessageBarComponent, TableOfContentComponent],
  template: `
    <div
      style="display:grid;grid-template-columns:minmax(14rem,16rem) minmax(0,1fr);gap:1rem;width:100%;max-width:62rem;padding:1rem;border:1px solid var(--color-neutral-stroke-rest);border-radius:1rem;background:var(--color-neutral-background-rest)"
    >
      <ui-table-of-content
        containerSelector=".toc-doc-layout-content"
        [sticky]="true"
        [offsetTop]="8"
        appearance="outline"
      />

      <div
        class="toc-doc-layout-content"
        style="display:flex;flex-direction:column;gap:1rem;min-width:0"
      >
        <ui-message-bar
          title="Draft documentation"
          message="This example shows TOC in a richer docs layout with callouts and section separators."
          variant="secondary"
          appearance="subtle"
          [dismissible]="false"
        />

        <h2 id="toc-doc-overview">Overview</h2>
        <p style="margin:0">
          TOC works best when the content column is already intentionally structured.
        </p>
        <ui-divider />
        <h2 id="toc-doc-recommendations">Recommendations</h2>
        <p style="margin:0">
          Keep the number of top-level sections manageable and avoid four layers unless the content
          truly needs it.
        </p>
        <h3 id="toc-doc-copy">Copy style</h3>
        <p style="margin:0">Headings should be scannable labels, not vague marketing phrases.</p>
        <ui-divider />
        <h2 id="toc-doc-reference">Reference</h2>
        <p style="margin:0">
          Reference-heavy pages benefit from a stable, always-visible contents rail.
        </p>
      </div>
    </div>
  `,
})
export class TableOfContentDocLayoutDemoComponent {}
```

## Accessibility

### Navigation semantics
`ui-table-of-content` renders a navigation region and internally maps its entries to tree-node based navigation items. The content area it indexes should still use meaningful heading structure.

### Keyboard behavior
Keyboard interaction follows the tree-node based row model used inside the component.

| Key | Action |
| --- | --- |
| Tab / Shift+Tab | Move focus into, through, and out of the table of contents. |
| Enter / Space | Activate the focused entry and scroll to the linked section. |
| ArrowRight / ArrowLeft | Expand or collapse nested TOC groups when deeper levels are present. |

### Heading structure
The TOC can only be as accessible and understandable as the source content. Use clear heading text, avoid skipping levels without reason, and prefer semantic headings over custom selectors when possible.
