Table of Contents (TOC)

Table of content component is a simple component that displays the current page's headings in a table of content format.

Examples Info

TOC component uses the IntersectionObserver Api. You can use all the options of the IntersectionObserver with the same attributes.

Default TOC

Default TOC works with native html heading elements (h1, h2, h3, etc..) with the usage of the dds-anchor class. dap-ds-typography heading variants (variant="h3" etc..) can be used also with the anchor attribute to generate the anchor links. You can see the example of this component on the right side of the page.

<dap-ds-toc header="Table of contents"></dap-ds-toc>
Heading levels

The TOC component can be configured to display only specific heading levels. The minHeadingLevel and maxHeadingLevel attribute can be used to set the levels. minHeadingLevel default value is 2, maxHeadingLevel default value is 3.

<dap-ds-toc header="Table of contents" minHeadingLevel="3" maxHeadingLevel="6"></dap-ds-toc>
Indentation

The TOC component items are indented by default. Setting the noIndent attribute to true will remove the indentation.

<dap-ds-toc header="Table of contents" noIndent></dap-ds-toc>
Importing
import { DapDSTOC } from 'dap-design-system/dist/dds'
Importing React
import { DapDSTOCReact } from 'dap-design-system/dist/react'
Slots

No slots available.

Attributes
PropertyTypeDefaultDescription
rootstring''The root element to observe IntersectionObserver
rootMarginstring'0px 0px -50% 0px'The margin around the root element to observe IntersectionObserver
thresholdnumber1The threshold to trigger IntersectionObserver
minHeadingLevelnumber2The minimum heading level to include in the TOC. The default value is 2.
maxHeadingLevelnumber3The maximum heading level to include in the TOC. The default value is 3.
noIndentbooleanfalseWhether to indent the TOC items.
headerstringThe header of the TOC.
Events
Event NameDescription
dds-anchor-changeEvent that is triggered when the anchor changes.
CSS Parts
Part NameDescription
baseThe main container of the toc.