DashboardSidebarCollapse
A button that collapses the sidebar to icons from the lg breakpoint up.
On this page
Examples
In a navbar
aria-expanded and aria-controls are kept up to date in the browser, so it works in static rendering.
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") },
];
}API
KlyDashboardSidebarCollapse
Button that collapses the dashboard sidebar to icons and expands it again.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
Class |
string |
Classes added to the root element, merged last so they win over the theme. | |
Color |
KlyColor |
"neutral" |
Semantic color of the dashboard sidebar collapse: a built-in KlyColor or the name of a color you defined. Values: primary, secondary, success, info, warning, error, neutral. |
For |
string |
The storage id of the sidebar to collapse. Defaults to the one of the enclosing group, or the sidebar of the same dashboard. | |
Label |
string |
Accessible name. Defaults to the built-in text. | |
Size |
KlySize |
KlySize. |
Size of the dashboard sidebar collapse, from Xs to Xl . When not set, Size applies, else the default of the component. Values: Xs, Sm, Md, Lg, Xl. |
Variant |
ButtonVariant |
ButtonVariant. |
Look of the button: Solid , Outline , Soft , Subtle , Ghost or Link . Values: Solid, Outline, Soft, Subtle, Ghost, Link. |