Skip to content

Some properties provide flexibility for specific integrations. Follow the component's usage guidance. Customizations beyond the documented patterns need a use case approved by DNB UX. Read about intended use and customization.

TableOfContent.Root#

TypeDefault valueDescription
childrenReact.ReactNodeNested TableOfContent.Item elements. Fragments and memoized items are supported. Use Data for generated content.
titleReact.ReactNode"On this page"Visible title and default accessible name. Translated through locale or the Provider locale.
localestringLanguage of the built-in title and show-all label. Overrides the Provider locale for this navigation only. Also sets its lang attribute unless lang is supplied. Custom titles and accessible names take precedence.
currentIdstring
null
Controlled current section id. Omit to detect it while scrolling. Set null to clear it. A section below maxDepth marks its nearest visible ancestor.
currentSectionOffsetnumber0Distance in pixels from the viewport top where a heading becomes current. Match the height of your sticky header.
maxDepthnumber2Number of visible levels, starting at the highest heading level below h1. Deeper headings remain tracked.
maxVisibleItemsnumber10Maximum number of links initially shown below the breakpoint, including nested links and an included page title. Set 0 to show every link. Desktop always shows all links.
breakpoint"small"
"medium"
"large"
"x-large"
"xx-large"
"large"Eufemia breakpoint above which the navigation is always expanded. At or below it, a disclosure button controls the list. Defaults to large (72em, normally 1152px); Provider breakpoint overrides are respected.
styleNoncestringCSP nonce for the inline styles used before hydration.
stretchbooleanfalseUse the available width. Otherwise the expanded sidebar is 12rem wide.
stickybooleantrueKeep the desktop navigation visible while its containing content scrolls. Set false when the application positions it.
stickyOffsetnumber
string
0Distance from the top of the scroll container. Numbers use pixels; strings accept CSS lengths.
animateChangesbooleanfalseAnimate heading-list changes with a short fade and staggered slide from the left. Initial rendering, section selection and collapsed lists are not animated. Respects reduced motion.
expandedbooleanControlled disclosure state below the breakpoint.
defaultExpandedbooleanfalseInitial disclosure state below the breakpoint.
expandedStorageKeystringStorage key used to remember the disclosure state across navigation and reloads. Stored booleans override defaultExpanded. Controlled expanded does not read or write storage.
expandedStorage"session"
"local"
"session"Storage used with expandedStorageKey. Session storage is recommended for navigation UI state.
refReact.Ref<HTMLElement>Reference to the navigation element.
[HTML attributes]VariousStandard nav attributes, including className, style, aria-label and aria-labelledby. A supplied accessible name takes precedence over the visible title.
[Space properties]VariousSupports spacing properties.

TableOfContent.Data#

TypeDefault valueDescription
dataArray<TableOfContentSection>REQUIREDFlat array of { id, text, level } in document order. Ids identify existing destinations and must be unique on the page. Text accepts inline React content. Level is the heading level from 1 to 6; h1 headings are tracked and shown when includeH1 is enabled.
[Root properties]VariousSupports TableOfContent.Root properties except children.
includeH1booleanfalseInclude level-1 page titles as links before their sections, without adding indentation or counting toward maxDepth.

TableOfContent.Item#

TypeDefault valueDescription
idstringREQUIREDUnique id of the heading or section to navigate to. It is not applied to the list item.
textReact.ReactNodeREQUIREDReadable link label. Supports inline formatting such as code. Avoid interactive content inside labels.
childrenReact.ReactNodeNested TableOfContent.Item elements.
[HTML attributes]VariousStandard list-item attributes, including className and style.

TableOfContentPreHydrationScript#

Import this helper from @dnb/eufemia/extensions/table-of-content/TableOfContentPreHydrationScript. It restores the saved disclosure styling before first paint in SSR and static pages. Place it after the navigation markup and before application hydration. It accepts standard script attributes, including nonce, except children and dangerouslySetInnerHTML.

The same module exports getPreHydrationScript for HTML templates assembled outside React. See disclosure persistence for placement and usage.

Translations#

More info about translations can be found in the general localization and Eufemia Forms localization docs.

Keynb-NOen-GBsv-SEda-DK
TableOfContent.showAllVis alleShow allVisa allaVis alle
TableOfContent.titlePå denne sidenOn this pagePå den här sidanPå denne side
Suggest an edit