Table of content component is a simple component that displays the current page's headings in a table of content format.
TOC component uses the IntersectionObserver Api. You can use all the options of the IntersectionObserver with the same attributes.
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>
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>
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>
import { DapDSTOC } from 'dap-design-system/dist/dds'
import { DapDSTOCReact } from 'dap-design-system/dist/react'
No slots available.
Property | Type | Default | Description |
---|---|---|---|
root | string | '' | The root element to observe IntersectionObserver |
rootMargin | string | '0px 0px -50% 0px' | The margin around the root element to observe IntersectionObserver |
threshold | number | 1 | The threshold to trigger IntersectionObserver |
minHeadingLevel | number | 2 | The minimum heading level to include in the TOC. The default value is 2 . |
maxHeadingLevel | number | 3 | The maximum heading level to include in the TOC. The default value is 3 . |
noIndent | boolean | false | Whether to indent the TOC items. |
header | string | The header of the TOC. |
Event Name | Description |
---|---|
dds-anchor-change | Event that is triggered when the anchor changes. |
Part Name | Description |
---|---|
base | The main container of the toc. |