DashboardSidebar
A resizable sidebar that collapses to icons and becomes an off-canvas panel below the lg breakpoint. It builds on Sidebar.
Examples
Collapse and resize
The collapse button and the mobile toggle are separate components, placed in the navbar.
Settings
Collapse the sidebar with the button next to the title, or drag its edge. Both are remembered in the browser.
Razor
@* The collapse button and the mobile toggle sit in the navbar, not in the sidebar: they find the sidebar through the
group. Below the lg breakpoint the sidebar is replaced by the toggle, which opens it as an off-canvas panel. *@
<div class="h-72 w-full overflow-hidden rounded-xl border border-(--klyroo-border)" data-testid="dashboard-sidebar-frame">
<KlyDashboardGroup StorageKey="playground-dashboard-sidebar">
<KlyDashboardSidebar As="KlyElement.Div" Width="224" Resizable data-testid="dashboard-sidebar-only" MobileTitle="Workspace">
<Header><span class="font-semibold text-(--klyroo-text-highlighted)">Acme</span></Header>
<ChildContent>
<KlyNavigationMenu Items="_items" Orientation="KlyOrientation.Vertical" AriaLabel="Sections" Ui="_navUi" />
</ChildContent>
</KlyDashboardSidebar>
<KlyDashboardPanel>
<Header>
<KlyDashboardNavbar Title="Settings">
<Leading><KlyDashboardSidebarCollapse data-testid="dashboard-sidebar-collapse" /></Leading>
</KlyDashboardNavbar>
</Header>
<Body>
<p class="text-sm text-(--klyroo-text-muted)">Collapse the sidebar with the button next to the title, or drag its edge. Both are remembered in the browser.</p>
</Body>
</KlyDashboardPanel>
</KlyDashboardGroup>
</div>
@code {
private static readonly NavigationMenuUi _navUi = new() { Label = "group-data-[state=collapsed]/sidebar:sr-only" };
private static readonly KlyNavigationItem[] _items =
[
new("Home") { Href = "/", Exact = true, Icon = KlyIcons.Named("home", "size-5") },
new("Messages") { Href = "/components/dashboard-sidebar", Icon = KlyIcons.Named("mail", "size-5") },
new("Settings") { Href = "/docs/theming", Icon = KlyIcons.Named("user", "size-5") },
];
}In a complete dashboard
Inbox
- Welcome to Acme
- Your invoice is ready
- Design review notes
- Weekly summary
- Password changed
Message
Press Ctrl+K, or use the search button, to jump to a page or run a command.
Last command: none
Razor
@* A complete dashboard in a frame of fixed height, so it does not replace the layout of the site. In an app the group
fills the page: give it the whole viewport. As="div": the docs page already has a main landmark.
The group-data-[state=collapsed]/sidebar variants keep labels for screen readers while the sidebar shows icons only. *@
<div class="h-[30rem] w-full overflow-hidden rounded-xl border border-(--klyroo-border)" data-testid="dashboard">
<KlyDashboardGroup StorageKey="playground-dashboard">
<KlyDashboardSidebar As="KlyElement.Div" Resizable data-testid="dashboard-sidebar">
<Header>
<span class="font-semibold text-(--klyroo-text-highlighted)">Acme</span>
</Header>
<ChildContent>
<KlyDashboardSearchButton data-testid="dashboard-search-button" />
<KlyNavigationMenu Items="_items" Orientation="KlyOrientation.Vertical" AriaLabel="Workspace" Ui="_navUi" />
</ChildContent>
<Footer>
<span class="inline-flex size-8 shrink-0 items-center justify-center rounded-full bg-(--klyroo-bg-elevated) text-xs font-medium" aria-hidden="true">AL</span>
<span class="min-w-0 truncate text-sm group-data-[state=collapsed]/sidebar:sr-only">Ada Lovelace</span>
</Footer>
</KlyDashboardSidebar>
<KlyDashboardPanel Resizable Size="35" MinSize="20" MaxSize="60" ResizeLabel="Resize inbox" data-testid="dashboard-inbox">
<Header>
<KlyDashboardNavbar Title="Inbox">
<Leading><KlyDashboardSidebarCollapse data-testid="dashboard-collapse" /></Leading>
</KlyDashboardNavbar>
<KlyDashboardToolbar>
<Left>
<KlyButton Label="All" Size="KlySize.Sm" Variant="ButtonVariant.Soft" Color="KlyColor.Neutral" />
<KlyButton Label="Unread" Size="KlySize.Sm" Variant="ButtonVariant.Ghost" Color="KlyColor.Neutral" />
</Left>
</KlyDashboardToolbar>
</Header>
<Body>
<ul class="flex flex-col gap-3 text-sm">
@foreach (var subject in _subjects)
{
<li class="truncate text-(--klyroo-text)">@subject</li>
}
</ul>
</Body>
</KlyDashboardPanel>
<KlyDashboardPanel data-testid="dashboard-detail">
<Header>
<KlyDashboardNavbar Title="Message" Toggle="false">
<Right>
<KlyButton Label="Reply" Size="KlySize.Sm" Variant="ButtonVariant.Outline" Color="KlyColor.Neutral" />
</Right>
</KlyDashboardNavbar>
</Header>
<Body>
<p class="text-sm text-(--klyroo-text-muted)">
Press Ctrl+K, or use the search button, to jump to a page or run a command.
</p>
<p class="text-sm text-(--klyroo-text-muted)" data-testid="dashboard-last">Last command: @(_last ?? "none")</p>
</Body>
</KlyDashboardPanel>
<KlyDashboardSearch Groups="_groups" OnSelect="item => _last = item.Label" />
</KlyDashboardGroup>
</div>
@code {
private string? _last;
private static readonly NavigationMenuUi _navUi = new() { Label = "group-data-[state=collapsed]/sidebar:sr-only" };
private static readonly string[] _subjects = ["Welcome to Acme", "Your invoice is ready", "Design review notes", "Weekly summary", "Password changed"];
private static readonly KlyNavigationItem[] _items =
[
new("Home") { Href = "/", Exact = true, Icon = KlyIcons.Named("home", "size-5") },
new("Inbox") { Href = "/components/dashboard-group", Icon = KlyIcons.Named("inbox", "size-5") },
new("Calendar") { Href = "/components/header", Icon = KlyIcons.Named("calendar", "size-5") },
new("Settings") { Href = "/docs/theming", Icon = KlyIcons.Named("user", "size-5") },
];
private static readonly KlyCommandGroup[] _groups =
[
new("Go to",
[
new() { Label = "Inbox", Href = "?view=inbox", Keywords = "mail messages" },
new() { Label = "Settings", Href = "?view=settings", Keywords = "preferences account" },
]),
new("Actions",
[
new() { Label = "Compose message", Keywords = "new write" },
new() { Label = "Sign out", Keywords = "logout" },
]),
];
}API
KlyDashboardSidebar
Sidebar for a dashboard: a column that collapses to icons and resizes from the lg breakpoint up, and an off-canvas panel below it.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
AriaLabel |
string |
Accessible name of the sidebar landmark. Defaults to the built-in text. | |
As |
KlyElement |
KlyElement. |
The element to render, Aside by default; use Div inside another landmark. Values: Div, Section, Article, Aside, Header, Footer, Main, Nav. |
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Collapsed (@bind-Collapsed) |
bool |
false |
The collapsed state when nothing is remembered. @bind-Collapsed follows and sets it from .NET. |
Collapsible |
bool |
false |
Also shows a collapse button in the header of the sidebar, besides KlyDashboardSidebarCollapse . |
Id |
string |
Overrides the storage id taken from the group. The first sidebar of a group uses the key of the group, the next ones that key followed by "-2", "-3"; set an Id to name one yourself, and give it to the controls with For . A sidebar with an Id takes no number, so the first sidebar without one still gets the key of the group. Don't give it the key of the group itself, or it shares its saved state and the controls without a target with that first sidebar. | |
MaxWidth |
int |
448 |
Largest width the user can resize the sidebar to, in pixels. Defaults to 448. |
MinWidth |
int |
192 |
Smallest width the user can resize the sidebar to, in pixels. Defaults to 192. |
MobileTitle |
string |
Title of the off-canvas panel shown on small screens. Defaults to the built-in text. | |
Resizable |
bool |
false |
Adds a handle on the edge to resize the sidebar with the mouse or the keyboard. Sizes are in pixels, unlike the panels. |
Ui |
SidebarUi |
Slot overrides, the same as KlySidebar . | |
Width |
int |
256 |
Initial width of the sidebar column, in pixels. Defaults to 256. |
Slots
| Name | Type | Description |
|---|---|---|
Footer |
RenderFragment |
Bottom of the sidebar: the signed-in user. |
Header |
RenderFragment |
Top of the sidebar: a logo and a title. Hidden while the sidebar is collapsed. |
ChildContent |
RenderFragment |
The scrollable middle: navigation, search button. |
Ui slots
Ui takes a SidebarUi with one class string per slot, merged after the theme.
| Slot | Styles |
|---|---|
Root |
Classes merged into the root slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Host |
Classes merged into the host slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Panel |
The wrapper of everything inside the aside but the resize handle; the panel takes its dialog role while it is open. |
Header |
Classes merged into the header slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
HeaderContent |
Classes merged into the headerContent slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Toggle |
Classes merged into the toggle slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
ToggleIcon |
Classes merged into the toggleIcon slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Content |
Classes merged into the content slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Footer |
Classes merged into the footer slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Handle |
Classes merged into the handle slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
Mobile |
The wrapper of the button that opens the panel (below lg). |
MobileHeader |
The title row of the panel, below lg. |
MobileTitle |
Classes merged into the mobileTitle slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |
MobileClose |
Classes merged into the mobileClose slot of KlyDashboardSidebar and KlySidebar , after the theme and the app configuration. |