Skip to content

Commit 9064860

Browse files
committed
docs: scroll selected side nav item into view
1 parent 74a5197 commit 9064860

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

docs/src/pages/_module.svelte

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import type { HeaderSearchResult } from "carbon-components-svelte/src/UIShell/HeaderSearch.svelte";
2121
import LogoGithub from "carbon-icons-svelte/lib/LogoGithub.svelte";
2222
import MiniSearch from "minisearch";
23-
import { onDestroy } from "svelte";
23+
import { onMount, tick } from "svelte";
2424
import SEARCH_INDEX from "../SEARCH_INDEX.json";
2525
import { theme } from "../store";
2626
@@ -47,7 +47,19 @@
4747
const unsubGoto = goto.subscribe((fn) => {
4848
navigateTo = fn;
4949
});
50-
onDestroy(unsubGoto);
50+
51+
onMount(() => {
52+
tick().then(() => {
53+
const selected = document.querySelector(
54+
'.bx--side-nav [aria-current="page"]',
55+
);
56+
selected?.scrollIntoView({ block: "center" });
57+
});
58+
59+
return () => {
60+
unsubGoto();
61+
};
62+
});
5163
5264
const deprecated: string[] = [];
5365
const new_components: string[] = [];

0 commit comments

Comments
 (0)