From 31189afd84b54a69390bef44c2ec005adca62356 Mon Sep 17 00:00:00 2001 From: Shewart Date: Sat, 10 Oct 2026 03:06:56 +0200 Subject: [PATCH 1/5] fix(chrome): desktop sidebar collapse without a Blazor runtime The collapse and expand buttons toggled SidebarCollapseState through @onclick, so they did nothing on a static export. They are now [data-sidebar-collapse-toggle] buttons handled by shelldocs.js, which flips [data-sidebar-collapsed] on the page shell and remembers the choice in localStorage; it's restored as soon as the script runs, so the sidebar doesn't flash open, and again after Blazor swaps the DOM. The expand toolbar is always rendered in the Sidebar layout and shown by CSS. SidebarCollapseState stays registered, unused. --- .../Chrome/DocsSidebarHeader.razor | 3 +- .../Chrome/SidebarCollapseState.cs | 3 +- .../Layouts/DocsLayout.razor | 15 ++-- .../Layouts/DocsLayout.razor.css | 11 +-- src/ShellDocs.Components/wwwroot/shelldocs.js | 27 +++++++ tests/ShellDocs.Tests/SidebarCollapseTests.cs | 72 +++++++++++++++++++ 6 files changed, 113 insertions(+), 18 deletions(-) create mode 100644 tests/ShellDocs.Tests/SidebarCollapseTests.cs diff --git a/src/ShellDocs.Components/Chrome/DocsSidebarHeader.razor b/src/ShellDocs.Components/Chrome/DocsSidebarHeader.razor index 1f9bb75..aaab0ca 100644 --- a/src/ShellDocs.Components/Chrome/DocsSidebarHeader.razor +++ b/src/ShellDocs.Components/Chrome/DocsSidebarHeader.razor @@ -1,7 +1,6 @@ @using ShellIcons.Icons @inject ShellDocsOptions Options @inject IJSRuntime JS -@inject SidebarCollapseState Collapse
@@ -9,7 +8,7 @@ @(!string.IsNullOrEmpty(Options.SiteName) ? Options.SiteName : "Docs") -
diff --git a/src/ShellDocs.Components/Chrome/SidebarCollapseState.cs b/src/ShellDocs.Components/Chrome/SidebarCollapseState.cs index 2b042a1..40b4823 100644 --- a/src/ShellDocs.Components/Chrome/SidebarCollapseState.cs +++ b/src/ShellDocs.Components/Chrome/SidebarCollapseState.cs @@ -1,7 +1,6 @@ namespace ShellDocs.Components.Chrome; -// Desktop collapse for the Sidebar layout — persistent, unlike the -// temporary mobile drawer in MobileNavState. +// No longer used: the sidebar collapse is driven by shelldocs.js. Kept so existing code compiles. public class SidebarCollapseState { public bool IsCollapsed { get; private set; } diff --git a/src/ShellDocs.Components/Layouts/DocsLayout.razor b/src/ShellDocs.Components/Layouts/DocsLayout.razor index 949c168..37ec33b 100644 --- a/src/ShellDocs.Components/Layouts/DocsLayout.razor +++ b/src/ShellDocs.Components/Layouts/DocsLayout.razor @@ -1,11 +1,11 @@ @inherits LayoutComponentBase -@inject ShellDocs.Components.Chrome.SidebarCollapseState Collapse @inject ShellDocsOptions Options @inject IJSRuntime JS -@implements IDisposable @using Microsoft.AspNetCore.Components.Sections -
+@* [data-sidebar-collapsed] is flipped by shelldocs.js ([data-sidebar-collapse-toggle]), + so collapsing works without a Blazor runtime. *@ +
@if (Options.LayoutVariant == DocsLayoutVariant.TopNav) { @@ -15,10 +15,11 @@ } - @if (Options.LayoutVariant == DocsLayoutVariant.Sidebar && Collapse.IsCollapsed) + @if (Options.LayoutVariant == DocsLayoutVariant.Sidebar) { + @* Shown by CSS while the sidebar is collapsed. *@
-