Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.4.1] - 2026-11-30

### Fixed

- **The Blazor glue called AdminLTE functions that don't exist.** `adminlte-blazor.js`
called `Treeview.init`, `PushMenu.init` and `CardWidget.init`, which AdminLTE 4
doesn't have, so nothing was re-initialised after Blazor replaced the prerendered
layout. On phones, tapping outside the open sidebar no longer closed it. The glue now
calls `adminlte.initialize()`, which removes the previous run's listeners before it
runs again, and recreates the sidebar's OverlayScrollbars instance when a DOM patch
removed it. `DashboardLayout` runs it once after the first interactive render
instead of on every render.
- **Statically rendered pages lost AdminLTE's setup after enhanced navigation.**
`<AdminLteScripts />` now also loads `adminlte-blazor.js` as a module, which re-runs
the setup on Blazor's `enhancedload` event.
- **Menu groups and dropdowns could navigate to the home page.** With
`blazor.web.js` loaded first, Blazor treated clicks on `href="#"` toggles as
navigation to `/` (via `<base href="/">`) on statically rendered pages. The docs and
the demo now load `<AdminLteScripts />` before `blazor.web.js`, and the topbar user
menu toggle is a `<button>`.
- **The sidebar stayed open over the new page after navigating on a phone.**
`DashboardLayout` now closes it after an interactive navigation below the sidebar
breakpoint.
- **Bootstrap's CSS was loaded twice.** `<adminlte-styles>` and `<AdminLteStyles />`
linked `bootstrap.min.css` as well as `adminlte.min.css`, which already contains
Bootstrap. The extra link (232 KB) is gone; the file still ships for anyone who
links it directly.
- **Sidebar accessibility.** The sidebar list no longer has `role="menu"` (it is site
navigation, not an application menu), matching AdminLTE 4.10.3, and the current
link has `aria-current="page"`.
- **README menu example threw on copy-paste.** It names a `RequireAdmin` policy that
was never registered; the example now registers it.

### Changed

- Bundled AdminLTE updated to **4.10.3**.

## [0.4.0] - 2026-11-17

### Changed
Expand Down
11 changes: 10 additions & 1 deletion NUGET.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ using ColorlibHQ.AdminLTE.AspNetCore;

builder.Services.AddAdminLte(builder.Configuration);
builder.Services.AddHttpContextAccessor(); // needed for the sidebar Tag Helper's active state

// The menu example below restricts its "Admin" item to a "RequireAdmin" policy.
// Register every policy your menu names, or remove "Policy" from the item: an
// unknown policy throws InvalidOperationException on every page with the sidebar.
builder.Services.AddAuthorization(options =>
options.AddPolicy("RequireAdmin", policy => policy.RequireRole("Admin")));
```

Define the menu in `appsettings.json`:
Expand All @@ -51,10 +57,13 @@ Reference the bundled CSS/JS in `App.razor` and wrap pages in `DashboardLayout`:
```razor
@* App.razor <head> *@
<AdminLteStyles />
@* …before </body>, after blazor.web.js *@
@* …at the end of <body>, BEFORE blazor.web.js *@
<AdminLteScripts />
<script src="_framework/blazor.web.js"></script>
```

Keep `<AdminLteScripts />` before `blazor.web.js`. AdminLTE's menu groups use `href="#"`, which `<base href="/">` turns into a link to the home page; Blazor leaves a click alone only if AdminLTE has already handled it, so AdminLTE has to load first. The components also re-run AdminLTE's setup after enhanced navigation and after the first interactive render, so the sidebar overlay, scrollbar and collapsed state survive page changes.

```razor
@* MainLayout.razor *@
@inherits LayoutComponentBase
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ using ColorlibHQ.AdminLTE.AspNetCore;

builder.Services.AddAdminLte(builder.Configuration);
builder.Services.AddHttpContextAccessor(); // needed for the sidebar Tag Helper's active state

// The menu example below restricts its "Admin" item to a "RequireAdmin" policy.
// Register every policy your menu names, or remove "Policy" from the item: an
// unknown policy throws InvalidOperationException on every page with the sidebar.
builder.Services.AddAuthorization(options =>
options.AddPolicy("RequireAdmin", policy => policy.RequireRole("Admin")));
```

Define the menu in `appsettings.json`:
Expand Down Expand Up @@ -106,10 +112,13 @@ Reference the bundled CSS/JS in your `App.razor` and wrap pages in `DashboardLay
```razor
@* App.razor <head> *@
<AdminLteStyles />
@* …before </body>, after blazor.web.js *@
@* …at the end of <body>, BEFORE blazor.web.js *@
<AdminLteScripts />
<script src="_framework/blazor.web.js"></script>
```

Keep `<AdminLteScripts />` before `blazor.web.js`. AdminLTE's menu groups use `href="#"`, which `<base href="/">` turns into a link to the home page; Blazor leaves a click alone only if AdminLTE has already handled it, so AdminLTE has to load first. The components also re-run AdminLTE's setup after enhanced navigation and after the first interactive render, so the sidebar overlay, scrollbar and collapsed state survive page changes.

```razor
@* MainLayout.razor *@
@inherits LayoutComponentBase
Expand Down
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ASP.NET Core package and publish it to [nuget.org](https://www.nuget.org/).

The package version is the `<Version>` element in
`src/ColorlibHQ.AdminLTE.AspNetCore/ColorlibHQ.AdminLTE.AspNetCore.csproj`.
Update it to the new release version (the port family currently tracks `0.2.0`):
Update it to the new release version:

```xml
<Version>0.2.0</Version>
Expand Down
5 changes: 3 additions & 2 deletions samples/AdminLte.Demo/Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
<body class="layout-fixed sidebar-expand-lg bg-body-tertiary">
<Routes @rendermode="InteractiveServer" />

<script src="_framework/blazor.web.js"></script>
@* Bootstrap bundle + AdminLTE JS, from the RCL. *@
@* Bootstrap bundle + AdminLTE JS, from the RCL. Before blazor.web.js, so their
click handlers cancel href="#" toggles before Blazor sees the click. *@
<AdminLteScripts />
<script src="_framework/blazor.web.js"></script>

@* CDN plugin libraries + the demo interop module for the JS-plugin pages. *@
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.6.1/dist/chart.umd.min.js" integrity="sha256-hzZMwrKnamaEkp59a4Cxiol3lNs4QAyv8fzxeRxpJdI=" crossorigin="anonymous"></script>
Expand Down
2 changes: 1 addition & 1 deletion samples/AdminLte.Demo/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"AdminLte": {
"BrandText": "AdminLTE 4",
"BrandUrl": "/",
"LogoImage": "https://cdn.jsdelivr.net/npm/admin-lte@4.10.2/dist/assets/img/AdminLTELogo.png",
"LogoImage": "https://cdn.jsdelivr.net/npm/admin-lte@4.10.3/dist/assets/img/AdminLTELogo.png",
"SidebarTheme": "dark",
"DefaultColorMode": "auto",
"ColorModeToggle": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<!-- NuGet package metadata -->
<PropertyGroup>
<PackageId>ColorlibHQ.AdminLTE.AspNetCore</PackageId>
<Version>0.4.0</Version>
<Version>0.4.1</Version>
<Authors>Colorlib</Authors>
<Company>Colorlib</Company>
<Product>AdminLTE 4 for ASP.NET Core</Product>
Expand All @@ -30,7 +30,7 @@
<!-- Drop a 128x128 docs/icon.png to brand the package; auto-included when present. -->
<PackageIcon Condition="Exists('..\..\docs\icon.png')">icon.png</PackageIcon>
<Copyright>Copyright (c) 2014-2026 Colorlib</Copyright>
<PackageReleaseNotes>Bundled AdminLTE 4.10.2 and Bootstrap 5.3.9 (print defaults, data-lte-print, data-lte-contrast, data-lte-primary). The demo now uses Chart.js instead of ApexCharts.</PackageReleaseNotes>
<PackageReleaseNotes>Fixes the Blazor glue: AdminLTE's setup now re-runs after the first interactive render and after enhanced navigation (sidebar overlay, scrollbar, collapsed state), and the sidebar closes after navigation on phones. Stylesheets no longer load Bootstrap twice. Sidebar drops role="menu" and marks the current link with aria-current. Bundled AdminLTE 4.10.3.</PackageReleaseNotes>
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
@* Blazor-friendly equivalent of the <adminlte-scripts> tag helper. Place near
the end of <body> in a Blazor App.razor, after blazor.web.js. *@
@* Blazor-friendly equivalent of the <adminlte-scripts> tag helper. Place it at the
end of <body> in App.razor, BEFORE <script src="_framework/blazor.web.js">.

Order matters: AdminLTE's toggles are href="#" links, and with <base href="/"> that
resolves to the home page. Blazor ignores clicks that were already cancelled, so
Bootstrap and AdminLTE must register their click handlers first; loaded after
blazor.web.js, a menu-group or dropdown click on a statically rendered page turns
into an enhanced navigation to "/".

adminlte-blazor.js is a module (it runs after blazor.web.js regardless of position)
that re-runs AdminLTE's setup after every enhanced navigation. *@

<script src="@($"{Base}/vendor/overlayscrollbars/js/overlayscrollbars.browser.es6.min.js")"></script>
<script src="@($"{Base}/vendor/bootstrap/js/bootstrap.bundle.min.js")"></script>
<script src="@($"{Base}/js/adminlte{Min}.js")"></script>
<script type="module" src="@($"{Base}/js/adminlte-blazor.js")"></script>

@code {
private const string Base = "/_content/ColorlibHQ.AdminLTE.AspNetCore";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@* Blazor-friendly equivalent of the <adminlte-styles> tag helper: renders the
AdminLTE/Bootstrap stylesheet links plus the no-flash color-mode script.
stylesheet links plus the no-flash color-mode script. adminlte.css already
contains Bootstrap's CSS, so Bootstrap's own stylesheet is not loaded.
Use in a Blazor App.razor <head>. (Tag Helpers don't run inside .razor.) *@

<link rel="stylesheet" href="@($"{Base}/vendor/bootstrap/css/bootstrap.min.css")" />
<link rel="stylesheet" href="@($"{Base}/vendor/bootstrap-icons/font/bootstrap-icons.min.css")" />
<link rel="stylesheet" href="@($"{Base}/vendor/overlayscrollbars/css/overlayscrollbars.min.css")" />
<link rel="stylesheet" href="@($"{Base}/css/adminlte{Min}.css")" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@* The full AdminLTE app shell: topbar + sidebar + content + footer.
Reads AdminLteOptions for branding/menu and the current path for active state.
Re-initialises AdminLTE's JS plugins after each interactive render. *@
Re-runs AdminLTE's setup once the layout becomes interactive. *@
@implements IAsyncDisposable
@inject IOptions<AdminLteOptions> Options
@inject IMenuService MenuService
Expand Down Expand Up @@ -81,6 +81,7 @@
private IReadOnlyList<MenuItem> _menu = Array.Empty<MenuItem>();
private CommandPalette? _palette;
private IJSObjectReference? _module;
private bool _navigated;

/// <summary>
/// Optional principal used to filter the menu/palette to authorized items.
Expand All @@ -101,17 +102,28 @@
{
_module = await JS.InvokeAsync<IJSObjectReference>(
"import", "./_content/ColorlibHQ.AdminLTE.AspNetCore/js/adminlte-blazor.js");
}
// Re-bind AdminLTE plugins to the freshly rendered DOM on every render.
if (_module is not null)
// The interactive render replaced the prerendered layout that AdminLTE set up on
// DOMContentLoaded (sidebar overlay, push-menu state, scrollbar). Set it up again.
await _module.InvokeVoidAsync("initAdminLte");
}
else if (_module is not null)
{
// Later renders patch the same elements; only restore the scrollbar if it was lost.
await _module.InvokeVoidAsync("refreshAdminLte");
if (_navigated)
{
_navigated = false;
await _module.InvokeVoidAsync("closeSidebarOnMobile");
}
}
}

private Task OpenPaletteAsync() => _palette?.OpenPalette() ?? Task.CompletedTask;

private void OnLocationChanged(object? sender, LocationChangedEventArgs e)
{
UpdateCurrentPath();
_navigated = true;
InvokeAsync(StateHasChanged);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

<nav class="mt-2" aria-label="Main navigation">
<ul id="navigation" class="nav sidebar-menu flex-column"
data-lte-toggle="treeview" data-accordion="@(Accordion ? "true" : "false")"
role="menu">
data-lte-toggle="treeview" data-accordion="@(Accordion ? "true" : "false")">
@foreach (var item in Items)
{
<SidebarNavItem Item="item" CurrentPath="@CurrentPath" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ else
{
<li class="nav-item">
<a href="@Item.ResolvedHref" target="@Item.Target"
class="nav-link @(IsActive(Item) ? "active" : null)">
class="nav-link @(IsActive(Item) ? "active" : null)"
aria-current="@(IsActive(Item) ? "page" : null)">
@if (!string.IsNullOrEmpty(Item.Icon))
{
<i class="nav-icon @Item.Icon @(string.IsNullOrEmpty(Item.IconColor) ? null : $"text-{Item.IconColor}")"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@
@if (User is not null)
{
<li class="nav-item dropdown user-menu">
<a href="#" class="nav-link dropdown-toggle d-flex align-items-center"
data-bs-toggle="dropdown" aria-expanded="false">
<button type="button" class="nav-link dropdown-toggle d-flex align-items-center"
data-bs-toggle="dropdown" aria-expanded="false">
@if (!string.IsNullOrEmpty(User.AvatarUrl))
{
<img src="@User.AvatarUrl" class="user-image rounded-circle shadow" alt="@User.Name" />
}
<span class="d-none d-md-inline">@User.Name</span>
</a>
</button>
<ul class="dropdown-menu dropdown-menu-lg dropdown-menu-end">
<li class="user-header text-bg-primary">
@if (!string.IsNullOrEmpty(User.AvatarUrl))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override async Task ProcessAsync(TagHelperContext context, TagHelperOutpu

// Menu
sb.Append("""<div class="sidebar-wrapper"><nav class="mt-2" aria-label="Main navigation">""");
sb.Append("""<ul class="nav sidebar-menu flex-column" data-lte-toggle="treeview" role="menu" id="navigation">""");
sb.Append("""<ul class="nav sidebar-menu flex-column" data-lte-toggle="treeview" id="navigation">""");
foreach (var item in menu)
RenderItem(sb, enc, item, currentPath);
sb.Append("</ul></nav></div></aside>");
Expand Down Expand Up @@ -83,7 +83,8 @@ private static void RenderItem(StringBuilder sb, HtmlEncoder enc, MenuItem item,
var active = IsActive(item, currentPath);
var target = string.IsNullOrEmpty(item.Target) ? "" : $""" target="{enc.Encode(item.Target)}""";
sb.Append("""<li class="nav-item">""");
sb.Append($"""<a href="{enc.Encode(item.ResolvedHref)}"{target} class="nav-link{(active ? " active" : "")}">""");
var state = active ? " class=\"nav-link active\" aria-current=\"page\"" : " class=\"nav-link\"";
sb.Append($"""<a href="{enc.Encode(item.ResolvedHref)}"{target}{state}>""");
AppendIcon(sb, enc, item);
sb.Append("<p>").Append(enc.Encode(item.Text ?? string.Empty));
AppendBadge(sb, enc, item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace ColorlibHQ.AdminLTE.AspNetCore.TagHelpers;

/// <summary>
/// Emits the <c>&lt;link&gt;</c> tags for Bootstrap, Bootstrap Icons, OverlayScrollbars
/// and AdminLTE from the package's static web assets, plus a blocking inline script
/// Emits the <c>&lt;link&gt;</c> tags for Bootstrap Icons, OverlayScrollbars and AdminLTE
/// (whose stylesheet already contains Bootstrap's CSS) from the package's static web assets, plus a blocking inline script
/// that applies the persisted color mode before first paint (no theme flash).
/// Usage in the <c>&lt;head&gt;</c>: <c>&lt;adminlte-styles /&gt;</c>.
/// </summary>
Expand All @@ -23,7 +23,6 @@ public override void Process(TagHelperContext context, TagHelperOutput output)

output.Content.SetHtmlContent(
$$"""
<link rel="stylesheet" href="{{Base}}/vendor/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="{{Base}}/vendor/bootstrap-icons/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="{{Base}}/vendor/overlayscrollbars/css/overlayscrollbars.min.css">
<link rel="stylesheet" href="{{Base}}/css/adminlte{{min}}.css">
Expand Down
Loading
Loading