Skip to content

fix: Find upper level heading of visible section - #4816

Merged
carlagn merged 3 commits into
mainfrom
fix/toc-depth-location
May 31, 2023
Merged

fix: Find upper level heading of visible section#4816
carlagn merged 3 commits into
mainfrom
fix/toc-depth-location

Conversation

@carlagn

@carlagn carlagn commented May 26, 2023

Copy link
Copy Markdown
Contributor

Describe this PR

The current way the TOC highlighting is structured does not identify for minor headings' placement. So as the default is 2, and the value of tocDepth is always minimum 2, we need to indentify at least the second level heading containing a particular intersected section.

For example: If we are located on a section under a h4 element, the tocDepth defines that not only will it only show headings at least up to the h2 level on the right, but it will not take into account any other headings, if they are intersecting. If we were to navigate to a section that is not included on the depth level of 2 or less, nothing would be highlighted on the right as the logic does not know which section that id belongs to.

So on a page like /concepts/components/prisma-client/raw-database-access#tagged-template-helpers, the visibleHeadings (before filtering based on tocDepth) and filteredVisible (after filtering) appear as such:

visibleHeadings filteredVisible
Screenshot 2023-05-26 at 16 24 24 Screenshot 2023-05-26 at 16 24 31

The goal of this PR is to have a solution that finds the visibleHeadings[0]'s (index 0 as we favor the top-most visible section) upper-level heading up to the h2 level.

Changes

Update toc's visibleHeadings logic.

before after
https://github.com/prisma/docs/assets/14851246/80677fb4-d732-416a-9200-fd5e30de1d0c https://github.com/prisma/docs/assets/14851246/02ed14a8-60a1-45be-8aff-98891b92885b

On the videos above you can see the difference on scrolling through a page (in this case, /concepts/components/prisma-client/raw-database-access)

What issue does this fix?

Fixes #3955

Any other relevant information

N/a

@vercel

vercel Bot commented May 26, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 29, 2023 0:18am

@github-actions

Copy link
Copy Markdown
Contributor

This PR changes the following pages (Vercel Preview Deploy links):

Changed Vercel links

(Note that links will only be valid after Vercel preview deploy succeeded)

@github-actions

Copy link
Copy Markdown
Contributor

This PR probably requires the following redirects to be added to vercel.json:

  • This PR does not change any pages in a way that would require a redirect.

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.

tagged-template-helpers anchor doesn't update side location indicator

2 participants