Layout
Scrollspy
Usage#
import { WDS_SCROLLSPY } from '@wds/angular/scrollspy';wds-scrollspy-item links with href="#id" in wds-scrollspy. Without target it follows the page; with target (a selector) it follows that scrolling element. The active item is the last section whose top has passed the reading line (the top of the scrolling area plus offset), and the last one once the area is scrolled to the end.
Examples#
Default#
target="#spy-default"). Clicking an item scrolls its section to the top and moves focus to it.
Planning
Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.
Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.
Gear
Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.
Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.
Weather
Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.
Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.
Camp
Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.
Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.
Leave no trace
Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.
Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.
import { Component } from '@angular/core';
import { WdsScrollspyComponent, WdsScrollspyItemComponent } from '@wds/angular/scrollspy';
@Component({
selector: 'app-scrollspy-default-demo',
imports: [WdsScrollspyComponent, WdsScrollspyItemComponent],
template: `
<div class="grid w-full max-w-2xl gap-6 sm:grid-cols-[10rem_1fr]">
<wds-scrollspy target="#spy-default">
<wds-scrollspy-item href="#spy-default-planning">Planning</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-default-gear">Gear</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-default-navigation">Navigation</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-default-weather">Weather</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-default-camp">Camp</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-default-leave-no-trace">Leave no trace</wds-scrollspy-item>
</wds-scrollspy>
<div id="spy-default" class="h-72 overflow-y-auto pr-4">
<section id="spy-default-planning" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Planning</h3>
<p class="mb-2 text-sm text-muted-foreground">Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.</p>
<p class="text-sm text-muted-foreground">Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.</p>
</section>
<section id="spy-default-gear" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Gear</h3>
<p class="mb-2 text-sm text-muted-foreground">Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.</p>
<p class="text-sm text-muted-foreground">Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.</p>
</section>
<section id="spy-default-navigation" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Navigation</h3>
<p class="mb-2 text-sm text-muted-foreground">A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.</p>
<p class="text-sm text-muted-foreground">At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.</p>
</section>
<section id="spy-default-weather" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Weather</h3>
<p class="mb-2 text-sm text-muted-foreground">Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.</p>
<p class="text-sm text-muted-foreground">Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.</p>
</section>
<section id="spy-default-camp" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Camp</h3>
<p class="mb-2 text-sm text-muted-foreground">Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.</p>
<p class="text-sm text-muted-foreground">Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.</p>
</section>
<section id="spy-default-leave-no-trace" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Leave no trace</h3>
<p class="mb-2 text-sm text-muted-foreground">Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.</p>
<p class="text-sm text-muted-foreground">Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.</p>
</section>
</div>
</div>
`,
})
export class ScrollspyDefaultDemo {}Levels#
level="2" indents an item under the one before it, for subsections. The levels only change the indent; the active item is still found by the position of each section.
Before you go
Two things decide most days in the hills before anyone ties their boots.
The rest of this part covers what to plan and what to pack.
Planning
Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.
Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.
Gear
Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.
Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.
On the trail
Once you are walking, attention matters more than speed.
These two habits prevent most of the trouble on a day route.
Weather
Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.
Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.
Overnight
Staying out after dark adds a few simple rules.
They protect you, the animals and the next people to camp here.
Camp
Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.
Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.
Leave no trace
Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.
Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.
import { Component } from '@angular/core';
import { WdsScrollspyComponent, WdsScrollspyItemComponent } from '@wds/angular/scrollspy';
@Component({
selector: 'app-scrollspy-levels-demo',
imports: [WdsScrollspyComponent, WdsScrollspyItemComponent],
template: `
<div class="grid w-full max-w-2xl gap-6 sm:grid-cols-[10rem_1fr]">
<wds-scrollspy target="#spy-levels">
<wds-scrollspy-item href="#spy-levels-before">Before you go</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-planning" level="2">Planning</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-gear" level="2">Gear</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-trail">On the trail</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-navigation" level="2">Navigation</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-weather" level="2">Weather</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-overnight">Overnight</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-camp" level="2">Camp</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-levels-leave-no-trace" level="2">Leave no trace</wds-scrollspy-item>
</wds-scrollspy>
<div id="spy-levels" class="h-72 overflow-y-auto pr-4">
<section id="spy-levels-before" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Before you go</h3>
<p class="mb-2 text-sm text-muted-foreground">Two things decide most days in the hills before anyone ties their boots.</p>
<p class="text-sm text-muted-foreground">The rest of this part covers what to plan and what to pack.</p>
</section>
<section id="spy-levels-planning" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Planning</h3>
<p class="mb-2 text-sm text-muted-foreground">Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.</p>
<p class="text-sm text-muted-foreground">Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.</p>
</section>
<section id="spy-levels-gear" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Gear</h3>
<p class="mb-2 text-sm text-muted-foreground">Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.</p>
<p class="text-sm text-muted-foreground">Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.</p>
</section>
<section id="spy-levels-trail" class="pb-6">
<h3 class="mb-2 text-base font-semibold">On the trail</h3>
<p class="mb-2 text-sm text-muted-foreground">Once you are walking, attention matters more than speed.</p>
<p class="text-sm text-muted-foreground">These two habits prevent most of the trouble on a day route.</p>
</section>
<section id="spy-levels-navigation" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Navigation</h3>
<p class="mb-2 text-sm text-muted-foreground">A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.</p>
<p class="text-sm text-muted-foreground">At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.</p>
</section>
<section id="spy-levels-weather" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Weather</h3>
<p class="mb-2 text-sm text-muted-foreground">Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.</p>
<p class="text-sm text-muted-foreground">Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.</p>
</section>
<section id="spy-levels-overnight" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Overnight</h3>
<p class="mb-2 text-sm text-muted-foreground">Staying out after dark adds a few simple rules.</p>
<p class="text-sm text-muted-foreground">They protect you, the animals and the next people to camp here.</p>
</section>
<section id="spy-levels-camp" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Camp</h3>
<p class="mb-2 text-sm text-muted-foreground">Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.</p>
<p class="text-sm text-muted-foreground">Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.</p>
</section>
<section id="spy-levels-leave-no-trace" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Leave no trace</h3>
<p class="mb-2 text-sm text-muted-foreground">Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.</p>
<p class="text-sm text-muted-foreground">Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.</p>
</section>
</div>
</div>
`,
})
export class ScrollspyLevelsDemo {}Horizontal#
orientation="horizontal" lays the items out as a bar above the content; the active item scrolls into view inside the bar when it does not fit.
Planning
Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.
Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.
Gear
Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.
Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.
Weather
Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.
Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.
Camp
Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.
Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.
Leave no trace
Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.
Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.
import { Component } from '@angular/core';
import { WdsScrollspyComponent, WdsScrollspyItemComponent } from '@wds/angular/scrollspy';
@Component({
selector: 'app-scrollspy-horizontal-demo',
imports: [WdsScrollspyComponent, WdsScrollspyItemComponent],
template: `
<div class="flex w-full max-w-2xl flex-col gap-4">
<wds-scrollspy orientation="horizontal" target="#spy-horizontal">
<wds-scrollspy-item href="#spy-horizontal-planning">Planning</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-horizontal-gear">Gear</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-horizontal-navigation">Navigation</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-horizontal-weather">Weather</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-horizontal-camp">Camp</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-horizontal-leave-no-trace">Leave no trace</wds-scrollspy-item>
</wds-scrollspy>
<div id="spy-horizontal" class="h-72 overflow-y-auto pr-4">
<section id="spy-horizontal-planning" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Planning</h3>
<p class="mb-2 text-sm text-muted-foreground">Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.</p>
<p class="text-sm text-muted-foreground">Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.</p>
</section>
<section id="spy-horizontal-gear" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Gear</h3>
<p class="mb-2 text-sm text-muted-foreground">Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.</p>
<p class="text-sm text-muted-foreground">Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.</p>
</section>
<section id="spy-horizontal-navigation" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Navigation</h3>
<p class="mb-2 text-sm text-muted-foreground">A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.</p>
<p class="text-sm text-muted-foreground">At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.</p>
</section>
<section id="spy-horizontal-weather" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Weather</h3>
<p class="mb-2 text-sm text-muted-foreground">Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.</p>
<p class="text-sm text-muted-foreground">Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.</p>
</section>
<section id="spy-horizontal-camp" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Camp</h3>
<p class="mb-2 text-sm text-muted-foreground">Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.</p>
<p class="text-sm text-muted-foreground">Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.</p>
</section>
<section id="spy-horizontal-leave-no-trace" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Leave no trace</h3>
<p class="mb-2 text-sm text-muted-foreground">Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.</p>
<p class="text-sm text-muted-foreground">Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.</p>
</section>
</div>
</div>
`,
})
export class ScrollspyHorizontalDemo {}Sticky header#
offset (here 56px) moves the reading line below it, both for marking the active section and for scrolling to one.
Planning
Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.
Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.
Gear
Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.
Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.
Weather
Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.
Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.
Camp
Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.
Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.
Leave no trace
Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.
Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.
import { Component } from '@angular/core';
import { WdsScrollspyComponent, WdsScrollspyItemComponent } from '@wds/angular/scrollspy';
@Component({
selector: 'app-scrollspy-offset-demo',
imports: [WdsScrollspyComponent, WdsScrollspyItemComponent],
template: `
<div class="grid w-full max-w-2xl gap-6 sm:grid-cols-[10rem_1fr]">
<wds-scrollspy target="#spy-offset" offset="56">
<wds-scrollspy-item href="#spy-offset-planning">Planning</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-offset-gear">Gear</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-offset-navigation">Navigation</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-offset-weather">Weather</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-offset-camp">Camp</wds-scrollspy-item>
<wds-scrollspy-item href="#spy-offset-leave-no-trace">Leave no trace</wds-scrollspy-item>
</wds-scrollspy>
<div id="spy-offset" class="h-72 overflow-y-auto pr-4">
<div class="sticky top-0 z-10 mb-4 border-b bg-background py-2 text-sm font-medium">Trail handbook</div>
<section id="spy-offset-planning" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Planning</h3>
<p class="mb-2 text-sm text-muted-foreground">Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.</p>
<p class="text-sm text-muted-foreground">Tell someone at home where you are going and when you expect to be back. Leave the plan in writing, with the trailhead and the latest time to raise the alarm.</p>
</section>
<section id="spy-offset-gear" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Gear</h3>
<p class="mb-2 text-sm text-muted-foreground">Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.</p>
<p class="text-sm text-muted-foreground">Carry more water than you think you need and a small first aid kit. A head torch weighs little and turns a late finish from dangerous into merely slow.</p>
</section>
<section id="spy-offset-navigation" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Navigation</h3>
<p class="mb-2 text-sm text-muted-foreground">A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.</p>
<p class="text-sm text-muted-foreground">At every junction stop and confirm the direction, even when the path looks obvious. Most wrong turns happen on wide, easy tracks where nobody is paying attention.</p>
</section>
<section id="spy-offset-weather" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Weather</h3>
<p class="mb-2 text-sm text-muted-foreground">Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.</p>
<p class="text-sm text-muted-foreground">Turning back is part of the plan, not a failure. Agree on a turnaround time before you leave and keep to it whatever the summit looks like.</p>
</section>
<section id="spy-offset-camp" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Camp</h3>
<p class="mb-2 text-sm text-muted-foreground">Choose flat ground away from dry stream beds and dead branches overhead. Pitch the tent with the door away from the wind and keep the stove outside it.</p>
<p class="text-sm text-muted-foreground">Hang or seal food overnight so that animals are not drawn to the tent. Keep a torch and warm clothes within reach in case you need to get up in the dark.</p>
</section>
<section id="spy-offset-leave-no-trace" class="pb-6">
<h3 class="mb-2 text-base font-semibold">Leave no trace</h3>
<p class="mb-2 text-sm text-muted-foreground">Take every wrapper and peel back down with you. Stay on the marked path, even when it is muddy, so that the edges do not widen year after year.</p>
<p class="text-sm text-muted-foreground">Use existing fire rings or skip the fire altogether. The best campsite is one that the next visitor cannot tell was used.</p>
</section>
</div>
</div>
`,
})
export class ScrollspyOffsetDemo {}Reading progress#
wds-change reports the id of the section being read (active) and the one before (previous); here it drives a title and a wds-progress above the article.
Planning
Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.
Gear
Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.
Weather
Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.
import { Component, computed, signal } from '@angular/core';
import { WdsProgressComponent } from '@wds/angular/progress';
import { WdsScrollspyComponent, WdsScrollspyItemComponent } from '@wds/angular/scrollspy';
const SECTIONS = [
{ id: 'planning', title: 'Planning', text: 'Pick a route that matches the slowest walker in the group, not the fastest. Check the distance, the total climb and where the trail leaves the road, then add an hour for breaks and photos.' },
{ id: 'gear', title: 'Gear', text: 'Boots you have already worn in, a rain shell and a warm layer go in every pack, even on a sunny morning. Above the tree line the wind can drop the temperature by ten degrees in minutes.' },
{ id: 'navigation', title: 'Navigation', text: 'A phone map is useful until the battery runs out. Bring a paper map of the area and look at it before you start, so the shapes of the valleys are familiar when you need them.' },
{ id: 'weather', title: 'Weather', text: 'Read the mountain forecast, not the one for the nearest town. Afternoon storms build quickly in summer, so plan to be off exposed ridges by early afternoon.' },
];
@Component({
selector: 'app-scrollspy-progress-demo',
host: { class: 'grid w-full max-w-2xl gap-6 sm:grid-cols-[10rem_1fr]' },
imports: [WdsProgressComponent, WdsScrollspyComponent, WdsScrollspyItemComponent],
template: `
<wds-scrollspy target="#spy-progress" (wdsChange)="active.set($event.active)">
@for (section of sections; track section.id) {
<wds-scrollspy-item [href]="'#spy-progress-' + section.id">{{ section.title }}</wds-scrollspy-item>
}
</wds-scrollspy>
<div class="flex flex-col gap-3">
<div class="flex flex-col gap-2">
<span class="text-sm font-medium">Reading: {{ current().title }}</span>
<wds-progress [value]="progress()" label="Reading progress" />
</div>
<div id="spy-progress" class="h-60 overflow-y-auto pr-4">
@for (section of sections; track section.id) {
<section [id]="'spy-progress-' + section.id" class="pb-24">
<h3 class="mb-2 text-base font-semibold">{{ section.title }}</h3>
<p class="text-sm text-muted-foreground">{{ section.text }}</p>
</section>
}
</div>
</div>
`,
})
export class ScrollspyProgressDemo {
protected readonly sections = SECTIONS;
/** `id` of the section being read, as reported by `wds-change`. */
protected readonly active = signal('');
private readonly index = computed(() => Math.max(0, SECTIONS.findIndex((s) => 'spy-progress-' + s.id === this.active())));
protected readonly current = computed(() => SECTIONS[this.index()]);
protected readonly progress = computed(() => ((this.index() + 1) / SECTIONS.length) * 100);
}API References#
wds-scrollspy-item#
wds-scrollspy to one section of the page. It is marked (active attribute and
aria-current="location") while its section is being read.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| href | string | '' | # and its id. |
| level | number | 1 |
Slots
| Slot | Description |
|---|---|
| (default) |
CSS parts (::part)
| Part | Description |
|---|---|
| link | <a> element. |
wds-scrollspy#
wds-scrollspy-item links to a section by href="#id";
the active one is the last section whose top has passed the reading line (the top of the scrolling area plus
offset), and the last one once the area is scrolled to the end, so a short final section is reached too.
It follows the page, or the scrolling element given by target. Clicking an item scrolls its section to the
reading line (smoothly, unless the user prefers reduced motion) and moves focus to it.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| target | string | '' | |
| offset | number | 0 | |
| orientation | WdsScrollspyOrientation | 'vertical' | vertical (a table of contents) or horizontal (a bar of links above the content). |
| label | string | '' | |
| active | string | '' | id of the section being read (without #). Set by the scrollspy; read it or listen to wds-change. |
Events
| Event | Description |
|---|---|
| wds-changeCustomEvent<WdsScrollspyChangeDetail> |
Methods
| Method | Description |
|---|---|
| refresh() | |
| scrollToSection(id: string) | id) to the reading line, marks it active and moves focus to it. |
Slots
| Slot | Description |
|---|---|
| (default) | wds-scrollspy-item elements. |
CSS parts (::part)
| Part | Description |
|---|---|
| nav | <nav> around the items. |
CSS custom properties
| Property | Description |
|---|---|
| --wds-scrollspy-gap |
Accessibility#
Screen reader#
<nav> named by label (by default „On this page”). The active item has aria-current="location".
tabindex="-1" if it is not focusable), so a screen reader reads on from there and Tab continues inside it.
Keyboard support#
| Key | Function |
|---|---|