Skip to content
Dashboard DashboardSidebarToggle

DashboardSidebarToggle

A button that opens the sidebar as an off-canvas panel below the lg breakpoint.

On this page

Examples

In a navbar

The navbar shows it by default. Narrow the window below the lg breakpoint to see it.

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

KlyDashboardSidebarToggle

Button that opens the off-canvas dashboard sidebar on small screens.

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 toggle: 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 open. 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.Md Size of the dashboard sidebar toggle, from Xs to Xl . When not set, Size applies, else the default of the component. Values: Xs, Sm, Md, Lg, Xl.
Variant ButtonVariant ButtonVariant.Ghost Look of the button: Solid , Outline , Soft , Subtle , Ghost or Link . Values: Solid, Outline, Soft, Subtle, Ghost, Link.