Repository navigation
How do you collapse the sidebar? #4213
Replies: 2 comments
|
Hi @yangxuan74! If you use If it is essential for you to collapse all groups even after user interaction, you could add a small client-side script to force them to close potentially: <script>
document
.querySelectorAll('.sidebar-content details:not(:has([aria-current="page"]))')
.forEach((details) => {
details.open = false;
});
</script> |
|
Thanks for your explanation. I implemented the auto-collapse effect using your method together with AI. If it's a user's first visit, not collapsing automatically does indeed help reduce navigation disorientation. If it's a returning user who is already familiar with the navigation and there are quite a few labels, collapsing automatically would be better. |

Hi @yangxuan74! If you use
collapsed: trueon each group it should only expand the group for the current page. However, once a user expands a group manually, Starlight respects that and will keep the group expanded on navigations until they collapse it manually again themselves. This ensures a more visually stable and less disorienting navigation experience.If it is essential for you to collapse all groups even after user interaction, you could add a small client-side script to force them to close potentially: