scrollspy

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package scrollspy attaches IntersectionObserver-based section tracking to any list of in-page anchors. As the user scrolls, the runtime sets `aria-current="true"` and `.is-active` on the anchor whose target is currently in view.

This is the standalone pattern extracted from the TOC widget's runtime — use it for sidebars, sticky in-page nav bars, or any list of `<a href="#id">` links that should reflect scroll position.

Wiring:

scrollspy.Wrap(scrollspy.Config{ObserveSelector: "main"},
    nestedlist.Render(nestedlist.Config{ Items: ... }),
)

The wrapping element gains `data-fui-scrollspy="<selector>"` and the runtime auto-loads `scrollspy.js` on first appearance.

Index

Constants

This section is empty.

Variables

View Source
var Style = registry.RegisterStyle("scrollspy", styleFn)

Style is the registered stylesheet handle. Wrap calls Style.WrapHTML so the data-fui-comp marker is emitted and the runtime auto-loads the CSS on first appearance.

Functions

func Wrap

func Wrap(cfg Config, child render.HTML) render.HTML

Wrap returns a `<div>` carrying the scrollspy data-attrs around `child`. The child is typically a nav list of `<a href="#id">` anchors (e.g. a `core-ui/patterns/nestedlist` render output).

Types

type Config

type Config struct {
	// ObserveSelector is a CSS selector for the region whose anchored
	// elements should be observed (e.g. "main", "article",
	// ".doc-body"). Required.
	ObserveSelector string

	// TargetSelector overrides the default "h2[id], h3[id]" — set it
	// when the section anchors aren't headings (e.g. "section[id]",
	// "[data-spy]").
	TargetSelector string

	// Class is appended to the wrapper's class list.
	Class string

	// ID optionally tags the wrapper.
	ID string
}

Config configures the scrollspy behavior.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL