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

[Bug]: docs-mode table-of-contents does not change URL when clicking on an anchor #26345

Open
kroeder opened this issue Mar 6, 2024 · 9 comments · May be fixed by #26459, #26482 or #30130
Open

[Bug]: docs-mode table-of-contents does not change URL when clicking on an anchor #26345

kroeder opened this issue Mar 6, 2024 · 9 comments · May be fixed by #26459, #26482 or #30130

Comments

@kroeder
Copy link
Member

kroeder commented Mar 6, 2024

Describe the bug

If you enable toc: true, docs-mode renders a table-of-contents inside the docs page.
When clicking on one of the toc list-items, the expected behavior would be to add the # anchor to the browser URL.

It should behave the same as clicking the # icon on a docs-page headline.

To Reproduce

https://stackblitz.com/edit/github-w91kck?file=.storybook%2Fpreview.ts

  • Open "Button / Docs"
  • Click on table of contents anchor -> nothing is added to the URL

System

No response

Additional context

No response

@vanessayuenn
Copy link
Contributor

@kroeder in the repro you provided, the TOC does link to the # anchor. Can you clarify how do you expect it to work differently?

@ftr93
Copy link

ftr93 commented Mar 6, 2024

@vanessayuenn yes, it links to the anchor correctly, but clicking it doesn't change the browser URL

@sooster910
Copy link

sooster910 commented Mar 7, 2024

I have confirmed the behavior @kroeder described: When hovering over the anchor tag, as shown in the image below, it behaves as expected. However, upon clicking, the browser URL does not update to reflect the clicked anchor tag.
It is supposed to scroll down to where the anchor tag is located.

image

@vanessayuenn Can I give it a try? Thanks.

@vanessayuenn
Copy link
Contributor

@sooster910 of course! We'd be thrilled to have your contribution. If this is your first contribution, be sure to check the contribution guide and hop onto the Storybook Discord if you need any help getting started. Looking forward to your PR! ✨

Diogorrib added a commit to Diogorrib/storybook that referenced this issue Mar 12, 2024
Bug - When toc:true is enabled, docs-mode renders a table-of-contents inside the docs page. Clicking a toc list-item does not change the URL.
Solution - Add a function so that the URL changes when clicking on a toc list-item.
@Diogorrib Diogorrib linked a pull request Mar 12, 2024 that will close this issue
8 tasks
@sooster910 sooster910 linked a pull request Mar 13, 2024 that will close this issue
8 tasks
@emlynmac
Copy link

emlynmac commented Nov 26, 2024

Just came across this issue in a repo I'm working with.

@sooster910 can you update your PR to no conflicts?
@vanessayuenn would you be able to review once the updates are made?

@sooster910
Copy link

Just came across this issue in a repo I'm working with.

@sooster910 can you update your PR to no conflicts? @vanessayuenn would you be able to review once the updates are made?

@emlynmac Sure. Given the conflicts with the original PR, I'll go ahead and create a new PR to address the issue from scratch.

@vanessayuenn once the new PR is up, I would appreciate it if you could review it. Thanks.

@kroeder
Copy link
Member Author

kroeder commented Nov 28, 2024

This could be related #29361

If you have an anchor hash value,

  1. On page load, it gets removed from the URL (which would make sharing the hash value of a toc-entry useless)
  2. When adding an anchor hash value, the page does not scroll to the anchor

@sooster910 by any chance, did your PR fix problem 2? If not, that's fine! I'm currently investigating #29361 myself

@sooster910
Copy link

This could be related #29361

If you have an anchor hash value,

  1. On page load, it gets removed from the URL (which would make sharing the hash value of a toc-entry useless)
  2. When adding an anchor hash value, the page does not scroll to the anchor

@sooster910 by any chance, did your PR fix problem 2? If not, that's fine! I'm currently investigating #29361 myself

@kroeder hi, the scrolling only works when you click the TOC now - the click handler updates the anchor, but if you type the anchor directly in the address bar, it doesn't work. Let me know if you need any clarification!

@Sidnioulz
Copy link
Member

Sidnioulz commented Dec 24, 2024

#30130 should fix this based on an initial PR from @sookmax.

I'd love for someone in this thread to check out that PR and confirm the bug is fixed for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment