Skip to content

Commit

Permalink
Assign all headers an id when layout mounts instead of waiting for Ta…
Browse files Browse the repository at this point in the history
…bleOfContents (which doesn't mount on mobile initially)
  • Loading branch information
techniq committed Jun 30, 2024
1 parent 882129d commit 47712a6
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/svelte-ux/src/routes/docs/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@
onMount(() => {
showTableOfContents = !hideTableOfContents && $xlScreen;
// Assign an `id` to every header element
const headers = document.querySelectorAll('h1, h2, h3, h4, h5, h6');
headers.forEach((header) => {
const id = header.innerHTML.toLowerCase().replace(/\s+/g, '_'); // Lowercase and convert spaces to underscores
header.setAttribute('id', id);
});
});
function getRelated(r: string) {
Expand Down

0 comments on commit 47712a6

Please sign in to comment.