Патерни
Навігація за розділами
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.
Зібрано з
Встановлення через CLI
volt composition потрібен @voltui/cli 1.4.0 або новіший. Остання версія в npm на момент збирання цієї сторінки — 1.3.3.recipes/section-nav. Одна команда записує всі файли нижче, а в режимі копіювання CLI — і компоненти, які вони імпортують; змінені вами компоненти залишаються як є.npx @voltui/cli composition add recipes/section-nav --mode=packagepackage · бекенд ng-primitives · потрібен @voltui/cli 1.4.0 або новіший.src/app/<тека>/, а скопійовані компоненти — до src/app/ui/; інші теки задайте через --path і --ui. Додайте --dry-run, щоб спершу побачити кожен файл.--track, щоб записати встановлене; згодом volt composition diff recipes/section-nav покаже, що змінили ви або еталон, не чіпаючи ваших файлів.Використання
pnpm add @voltui/components