Installation
import { WrAnchor } from 'ngwr/anchor';
@Component({ imports: [WrAnchor] })
export class MyComponent {}Demo
The anchor below tracks the headings as you scroll the showcase page. Spacers between sections give the scroll-spy something to react to.
<wr-anchor [links]="links" [offset]="80" />API
Inputs of <wr-anchor>.
| Name | Description | Type | Default |
|---|---|---|---|
links | — | readonly WrAnchorLink[] | [] |
ariaLabel | Accessible name for the navigation landmark. Falls back to anchor.label, then 'Table of contents' — it used to be that English string, hard-coded on the host, in a landmark a screen reader reads out on every page. | string | null | null |
offset | Pixel offset subtracted on scroll — for sticky headers. | number | 0 |
hitArea | Highlight an item when its target's top is within this many px of the offset line. | number | 80 |
Types
Data shapes used by the inputs above.
interface WrAnchorLink {
id: string;
label: string;
children?: readonly WrAnchorLink[];
}| Name | Description | Type | Default |
|---|---|---|---|
WrAnchorLink | One entry in the rail. | interface | — |
idrequired | Target element id (without #). | string | — |
labelrequired | Visible text. | string | — |
children | One level of nested links. | readonly WrAnchorLink[] | — |