Patrones

Navegación por secciones

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.

Construido con

Instalar con el CLI

Aún no está en npm: volt composition requiere @voltui/cli 1.4.0 o posterior. La última versión en npm cuando se generó esta página era la 1.3.3.
Id estable recipes/section-nav. Un solo comando escribe todos los archivos de abajo y, en modo copia del CLI, los componentes que importa; los componentes que hayas personalizado se conservan tal cual.
npx @voltui/cli composition add recipes/section-nav --mode=package
Modo package · backend ng-primitives · necesita @voltui/cli 1.4.0 o posterior.Los archivos van a src/app/<carpeta>/ y los componentes copiados a src/app/ui/; elige otras carpetas con --path y --ui. Añade --dry-run para ver antes cada archivo.Añade --track para registrar lo instalado; después, volt composition diff recipes/section-nav muestra qué cambiaste tú o la referencia sin tocar tus archivos.

Uso

Instalar por CLI:pnpm add @voltui/components
TypeScript
Cargando el editor…