Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
help: Scroll to selected menu item in left sidebar if not in view.
Shubham Padiaddc56f7315d7
diff --git a/starlight_help/astro.config.mjs b/starlight_help/astro.config.mjsindex a813cfc920f..f058c08ee31 100644--- a/starlight_help/astro.config.mjs+++ b/starlight_help/astro.config.mjs@@ -156,6 +156,7 @@ export default defineConfig({components: {Footer: "./src/components/Footer.astro",Head: "./src/components/Head.astro",+ Sidebar: "./src/components/Sidebar.astro",},pagination: false,routeMiddleware: "./src/route_data.ts",diff --git a/starlight_help/src/components/Sidebar.astro b/starlight_help/src/components/Sidebar.astronew file mode 100644index 00000000000..e836d32fef7--- /dev/null+++ b/starlight_help/src/components/Sidebar.astro@@ -0,0 +1,25 @@+---+import DefaultSidebar from "@astrojs/starlight/components/Sidebar.astro";+---++<DefaultSidebar />++<script is:inline>+ const scrollSelectedItemIntoView = () => {+ const sidebar = document.getElementById("starlight__sidebar");+ const selectedItem = sidebar?.querySelector('[aria-current="page"]');+ if (!sidebar || !(selectedItem instanceof HTMLElement)) return;++ const sidebarRect = sidebar.getBoundingClientRect();+ const selectedItemRect = selectedItem.getBoundingClientRect();+ const isVisible =+ selectedItemRect.top >= sidebarRect.top &&+ selectedItemRect.bottom <= sidebarRect.bottom;++ if (!isVisible) {+ selectedItem.scrollIntoView({block: "center"});+ }+ };++ scrollSelectedItemIntoView();+</script>