Install
Add the package to your project.
With npm
Run npm install @focsd-dev/components.
Usage
Write the elements in your HTML.
A list of links to the headings on the page that marks the section you are reading.
Add the package to your project.
Run npm install @focsd-dev/components.
Write the elements in your HTML.
<focsd-table-of-contents for="#guide"></focsd-table-of-contents><article id="guide"> <h2>Install</h2> <p>Add the package to your project.</p> <h3>With npm</h3> <p>Run npm install @focsd-dev/components.</p> <h2>Usage</h2> <p>Write the elements in your HTML.</p></article>Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.
<script type="module"> import '@focsd-dev/components/focsd-table-of-contents.js';</script>
<focsd-table-of-contents for="#guide"></focsd-table-of-contents>import { TableOfContents } from '@focsd-dev/react';
export function Example() { return <TableOfContents for="#guide"></TableOfContents>;}<script setup>import '@focsd-dev/components/focsd-table-of-contents.js';</script>
<template> <focsd-table-of-contents for="#guide"></focsd-table-of-contents></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/components/focsd-table-of-contents.js';
// template<focsd-table-of-contents for="#guide"></focsd-table-of-contents><script> import '@focsd-dev/components/focsd-table-of-contents.js';</script>
<focsd-table-of-contents for="#guide"></focsd-table-of-contents>| Attribute | Property | Type | Default |
|---|---|---|---|
for | for | string | main, focsd-app-shell |
levels | levels | string | 2,3 |
label | label | string | — |
| Slot | Description |
|---|---|
(default) | Optional links (a[href^="#"]) that replace the generated list; their targets are tracked. |
Style the inside of the component with ::part(), for example focsd-table-of-contents::part(nav).
| Part | Description |
|---|---|
nav | The navigation landmark. |
list | Each list of links; a nested list is inside the item of its parent heading. |
link | Each generated link. |
label when a page has more than one.h2 and h3 headings of the first element matching for (by default main, or focsd-app-shell). Set levels to choose others, such as levels="2". An h3 is nested in a list under the h2 before it.id gets one made from its text, so its link and the address bar point at it.aria-current="location", which screen readers read as "current location".#id to the address, so Back returns to where you were.a[href^="#"]) inside to replace the generated list; the current section is still marked on them.| Key | Action |
|---|---|
| Tab | Move between links |
| Enter | Go to the heading and focus it |
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.