Skip to content

On This Page

A table of contents whose dot rides a thin rail with the scroll, bending in to fold open each section's subsections as you reach them.

3 variantsNew

Preview

Installation

Copies the component into components/ui and installs its dependencies and theme tokens.

pnpm dlx shadcn@latest https://floret.shippedui.com/r/on-this-page.json

Usage

Pass your own data and wire the callbacks to your app.

import { OnThisPage } from "@/components/ui/on-this-page";

// Each id must match an element on the page, like <h2 id="install">.
const sections = [
  { id: "intro", title: "Introduction" },
  {
    id: "install",
    title: "Installation",
    children: [
      { id: "install-cli", title: "With the CLI" },
      { id: "install-manual", title: "By hand" },
    ],
  },
  { id: "usage", title: "Usage" },
];

export function DocsSidebar() {
  return (
    <aside className="sticky top-24 w-56">
      <OnThisPage sections={sections} />
    </aside>
  );
}

Props

PropTypeDefaultDescription
sections*Section[]—The page's sections in order, each with an optional list of subsections.
containerRefObject<HTMLElement | null>—The element that scrolls, when it isn't the window. Section ids are looked up inside it.
labelstring"On this page"Heading above the list; also the nav's accessible name.
offsetnumber96Distance in px from the top of the scroller where a section counts as current. Match your sticky header.
maxSubsectionsnumber5Most subsections shown at once; the rest slide in as you go, with More above / More below rows. 0 shows all.
insetnumber18How far in, in px, the subsection line sits from the main line.
curvenumber0.5Softness of the bend between the two lines. 0.5 is a classic S; lower is tighter.
rowHeightnumber30Height of one row, px.
sectionGapnumber4Extra space above each new section, px.
subsectionGapnumber0Space between subsections, px. Negative values pull them closer.
bendRoomnumber8Extra space above a group's first subsection, giving the bend more room, px.
lineWidthnumber2Width of the rail, px.
dotSizenumber8Diameter of the dot, px.
classNamestring—Classes for the nav.
type SubSection = { id: string; title: string };

// A section, optionally with one level of subsections.
type Section = SubSection & { children?: readonly SubSection[] };