diff --git a/skills/tedi-angular/references/components.md b/skills/tedi-angular/references/components.md index 31cd1a398..9e7ea4f7a 100644 --- a/skills/tedi-angular/references/components.md +++ b/skills/tedi-angular/references/components.md @@ -422,6 +422,10 @@ Both entry points declare `[tedi-floating-button]`. The Community component is adds drag to close, snap points and a collapsed state, and with `showOverlay`, `trapFocus` and `lockScroll` off (plus `closeOnBackdropClick` off) it stays docked while the page behind remains usable. +- **`scrollSpy()` over a hand-written `IntersectionObserver` for `tedi-table-of-contents`.** The TOC + is controlled via `activeId`; `scrollSpy({ ids, scrollContainer, offset })` returns that id as a + signal plus `scrollToSection(id)` for the item links' click handlers. Sections are looked up when + `ids` changes, so when they render later (`@if`, `@defer`) pass `ids` as a signal that updates then. ### Responsive behaviour that isn't an input diff --git a/src/tedi/components/navigation/table-of-contents/table-of-contents.stories.ts b/src/tedi/components/navigation/table-of-contents/table-of-contents.stories.ts index dbb0b0a26..2f9d46f95 100644 --- a/src/tedi/components/navigation/table-of-contents/table-of-contents.stories.ts +++ b/src/tedi/components/navigation/table-of-contents/table-of-contents.stories.ts @@ -1,14 +1,5 @@ -import { isPlatformBrowser, NgTemplateOutlet } from "@angular/common"; -import { - Component, - effect, - ElementRef, - inject, - OnDestroy, - PLATFORM_ID, - signal, - viewChild, -} from "@angular/core"; +import { NgTemplateOutlet } from "@angular/common"; +import { Component, computed, ElementRef, viewChild } from "@angular/core"; import { Meta, StoryObj, moduleMetadata } from "@storybook/angular"; import { VISUAL_TEST_VIEWPORTS, @@ -20,6 +11,7 @@ import { IconComponent } from "../../base/icon/icon.component"; import { TextComponent } from "../../base/text/text.component"; import { HideAtDirective } from "../../../directives/hide-at/hide-at.directive"; import { ShowAtDirective } from "../../../directives/show-at/show-at.directive"; +import { scrollSpy } from "../../../utils/scroll-spy.util"; import { LinkComponent } from "../link/link.component"; import { TableOfContentsComponent } from "./table-of-contents.component"; import { TableOfContentsCollapsibleComponent } from "./table-of-contents-collapsible/table-of-contents-collapsible.component"; @@ -652,9 +644,8 @@ const CHAPTERS: DemoSection[] = Array.from({ length: 30 }, (_, i) => { * Example for the StickyInLayout story: a documentation page with a sticky * table-of-contents sidebar. The window scrolls, the sticky TOC stays alongside * it and scrolls on its own when taller than the viewport. Below `lg` the - * sidebar collapses into `tedi-table-of-contents-collapsible`. The component is - * controlled via `activeId`: an `IntersectionObserver` highlights the section in - * view (scroll-spy) and clicking an item smooth-scrolls the page to it. + * sidebar collapses into `tedi-table-of-contents-collapsible`. `activeId` comes + * from `scrollSpy`. */ @Component({ selector: "toc-sticky-demo", @@ -688,7 +679,7 @@ const CHAPTERS: DemoSection[] = Array.from({ length: 30 }, (_, i) => { -