Staaarter

Scroll-Spy Sticky Sidebar Feature

A feature section with a sticky left-hand navigation sidebar and a scrolling right-hand column of image-led feature sections. The sidebar link for whichever section is currently in view is highlighted automatically as the visitor scrolls.

By Staaarter Team
Feature
Docs
Live preview

Docs

Installation

A real shadcn registry command, not a copy-paste stand-in: it fetches this block plus its media-slot dependencies and any missing npm packages, and installs them straight into your project.

npx shadcn add https://staaarter.com/r/scroll-spy-sticky-sidebar-feature.json

Prefer not to use the CLI? Copy the source from the Code toggle above into src/components/blocks/feature/feature105.tsx instead.

Usage

The file also exports feature105Demo, the exact props behind the preview above. Spread it to get a working section in one line, then replace it with your own data.

import { Feature105, feature105Demo } from "@/components/blocks/feature/feature105";

export default function Page() {
  return <Feature105 {...feature105Demo} />;
}

Props

PropTypeDefaultDescription
eyebrowstringundefinedSmall label above the heading; omitted entirely when unset.
headingReactNodenoneSection heading.
sectionsScrollSpyFeatureSection[]noneFeature sections rendered in the scrolling column; each needs a unique id.
classNamestringundefinedExtra classes for the outer section element.

Types

type ScrollSpyFeatureSection = {
  id: string;
  navLabel: string;
  title: string;
  description: string;
  image: { src: string; alt: string };
};

Behavior notes

  • Real scroll-spy: a useEffect wires up an IntersectionObserver (rootMargin -15% top / -60% bottom) over every section's element, and the currently-intersecting section's id is written to activeId state, which drives which sidebar link is highlighted.
  • The sidebar itself uses CSS position: sticky (lg:sticky lg:top-24), not JS, to stay in view while the right-hand column scrolls; the JS only tracks which link should be highlighted.
  • The sidebar nav is hidden below the lg breakpoint (hidden lg:block) since there's no room for a persistent side column on narrow viewports; sections still stack and scroll normally on mobile.
  • Each sidebar link is a plain anchor to its section's id (`#id`) with `scroll-mt-24` on the target so a jump doesn't hide the heading under a sticky header.
  • "use client" component, so its demo props live in the sibling feature105.demo.tsx file per this repo's client/demo-file-split rule, not in feature105.tsx itself.