Skip to content
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

Issues with highlighting the correct content #50

Open
vamshinenu opened this issue Dec 31, 2023 · 1 comment
Open

Issues with highlighting the correct content #50

vamshinenu opened this issue Dec 31, 2023 · 1 comment
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@vamshinenu
Copy link

when I was in your web page I was trying to move around, and found out that.
when I click on Usage and back on Examples the highlight is still on Usage tables of content. and for another example

when you are on top, try clicking on the bottom line Test Page Navigation it was highlighting on Styling instead.

@janosh
Copy link
Owner

janosh commented Jan 15, 2024

Unfortunately, that's a known shortcoming of the set_active_heading implementation using activeHeadingScrollOffset to determine which heading is active.

function set_active_heading() {
let idx = headings.length
while (idx--) {
const { top } = headings[idx].getBoundingClientRect()
// loop through headings from last to first until we find one that the viewport already
// scrolled past. if none is found, set make first heading active
if (top < activeHeadingScrollOffset || idx === 0) {
activeHeading = headings[idx]
activeTocLi = tocItems[idx]
// this annoying hackery to wait for scroll end is necessary because scrollend event only has 2%
// browser support https://stackoverflow.com/a/57867348 and Chrome doesn't support multiple
// simultaneous scrolls, smooth or otherwise (https://stackoverflow.com/a/63563437)
clearTimeout(scroll_id)
scroll_id = window.setTimeout(() => {
if (keepActiveTocItemInView && activeTocLi) {
// get the currently active ToC list item
// scroll the active ToC item into the middle of the ToC container
nav.scrollTo?.({
top: activeTocLi?.offsetTop - nav.offsetHeight / 2,
behavior: `smooth`,
})
}
}, 50)
return // exit while loop if updated active heading
}
}
}

While I think there's no perfect solution here (e.g. "clicking on the bottom line Test Page Navigation it was highlighting on Styling instead" seems unavoidable if headings are nearby) I readily admit this could likely be improved. PRs welcome!

@janosh janosh added help wanted Extra attention is needed bug Something isn't working labels Jan 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants