Skip to content

Dynamic TOC height #3233

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Dynamic TOC height #3233

wants to merge 6 commits into from

Conversation

zenoachtig
Copy link
Contributor

@zenoachtig zenoachtig commented May 13, 2025

This PR adds a client-side available height calculation for the TableOfContents component. This solves two issues:

  • When the announcement banner is enabled, the TOC's static height is too high to fit in the screen initially. When scrolling down the banner disappears out of frame, which means the TOC needs to grow to take the available height (causing issues like RND-7090)
  • When reaching the footer, the TOC bumps up against it and moves visually up the screen, with its top part cut off. We should subtract the footer's visible height from the TOC height.

Important to note: to prevent layout shift the TOC still has a number of top-* and h-* classes added to it, to set its initial positioning as close as possible on the server. Once the client loads we override these classes with the dynamic height through CSS variables.

Before

CleanShot.2025-05-14.at.11.04.20.mp4

After

CleanShot.2025-05-14.at.11.07.12.mp4

Fixes RND-7090

Copy link

changeset-bot bot commented May 13, 2025

🦋 Changeset detected

Latest commit: d61db35

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
gitbook Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refines the styling and behavior of the TableOfContents by accounting for the announcement banner height and other header variations. Key changes include:

  • Updating Tailwind configuration variants to accommodate new header and announcement states.
  • Introducing a client-side script (TableOfContentsScript) for dynamic TOC positioning.
  • Migrating from the legacy TableOfContents export to a more adaptive component (AdaptiveTableOfContents) and updating related layout and styling.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/gitbook/tailwind.config.ts Updated variant selectors to improve header and announcement styling.
packages/gitbook/src/components/TableOfContents/index.ts Refactored exports to include AdaptiveTableOfContents and additional modules.
packages/gitbook/src/components/TableOfContents/TableOfContentsScript.tsx Added a new client-side script for dynamic TOC size and position adjustments.
packages/gitbook/src/components/TableOfContents/TableOfContents.tsx Adjusted class names and included new dynamic positioning and announcement variants.
packages/gitbook/src/components/TableOfContents/AdaptiveTableOfContents.tsx Created a wrapper for combining server-rendered TOC with dynamic behavior.
packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx Replaced TableOfContents with AdaptiveTableOfContents for enhanced functionality.
packages/gitbook/src/components/RootLayout/globals.css Updated CSS selector for announcement banner to use an ID instead of a class.
packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx Modified header class handling to use an array-based syntax for conditional classes.
packages/gitbook/src/components/Announcement/AnnouncementBanner.tsx Assigned an ID to the banner element, ensuring consistency with the new selectors.
Comments suppressed due to low confidence (1)

packages/gitbook/src/components/RootLayout/CustomizationRootLayout.tsx:79

  • Ensure that the tcls class concatenation helper correctly handles arrays of classes; if not, convert the array to a space-delimited string before passing it to avoid unexpected behavior.
: ['site-header', 'scroll-pt-[76px]'], // Take the sticky header in consideration for the scrolling

Copy link

argos-ci bot commented May 13, 2025

The latest updates on your projects. Learn more about Argos notifications ↗︎

Build Status Details Updated (UTC)
customers-v1 (Inspect) 👍 Changes approved 2 changed May 14, 2025, 10:09 AM
customers-v2 (Inspect) 👍 Changes approved 2 changed May 14, 2025, 10:11 AM
default (Inspect) 👍 Changes approved 8 changed May 14, 2025, 10:12 AM
v2-cloudflare (Inspect) 👍 Changes approved 4 changed May 14, 2025, 10:12 AM
v2-vercel (Inspect) 👍 Changes approved 4 changed May 14, 2025, 10:13 AM

Copy link

linear bot commented May 14, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant