Patterns
Section navigation
Overview
Long pages need a way to say where you are. This navigation follows the reader as they scroll and highlights the section on screen.
It is built from native anchors, so middle-click, copy link and deep links to a section all work without any code.
Installation
Nothing to install: copy this file, replace the section list and the demo content, and the observer does the rest.
Sections are found by id in the document, so the content can live anywhere on the page, not only inside this component.
Configuration
Set the sticky offset to the height of your header, and the same value is used as the scroll margin of every section.
The reading band is the top 40% of the scroll area: the active section is the first one that reaches it.
Accessibility
The current link carries aria-current="location". Arrow keys move between links; Tab and Enter work as on any anchor.
Smooth scrolling is applied only when the visitor has not asked for reduced motion.
FAQ
The last section is often shorter than the screen and can never reach the top. Clicking its link still marks it active.
If your sections load later, change the input: the observer is rebuilt for the new list and the old one is disconnected.
Built from
Install with the CLI
volt composition needs @voltui/cli 1.4.0 or later. The latest version on npm when this page was built was 1.3.3.recipes/section-nav. One command writes every file below and, in CLI-copy mode, the components it imports; components you customised are kept as they are.npx @voltui/cli composition add recipes/section-nav --mode=packagepackage · backend ng-primitives · needs @voltui/cli 1.4.0 or later.src/app/<folder>/ and copied components to src/app/ui/; choose others with --path and --ui. Add --dry-run to see every file first.--track to record what was installed; later, volt composition diff recipes/section-nav shows what you or the reference changed without touching your files.Usage
pnpm add @voltui/components