Navigation Menu

Top navigation bar with new NavItem, NavList, NavTrigger, and NavContent subcomponents.

v0.3.0 adds NavList, NavItem, NavTrigger, and NavContent subcomponents for a fully compositional navigation pattern.

What changed from v0.2.x

v0.2.1 v0.3.0
<NavigationMenuItem Title="..." HasContent="true"> items <NavItem><NavTrigger>...</NavTrigger><NavContent>...</NavContent></NavItem>
Title string parameter NavTrigger takes any RenderFragment

Installation

bash
shellui add navigation-menu nav-item nav-list nav-trigger nav-content

Usage

Basic navigation with dropdowns

@* Height leaves room for the open panel inside the preview. *@
<div class="flex h-52 items-start">
    <div class="rounded-lg border border-border bg-background p-1">
        <NavigationMenu>
            <NavList>
                <NavItem>
                    <NavTrigger>Products</NavTrigger>
                    <NavContent>
                        <a href="/docs/components" class="block rounded-sm px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground">Components</a>
                        <a href="/docs/theming" class="block rounded-sm px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground">Themes</a>
                        <a href="/docs/dashboard" class="block rounded-sm px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground">Dashboard layout</a>
                    </NavContent>
                </NavItem>
                <NavItem>
                    <NavTrigger>Docs</NavTrigger>
                    <NavContent>
                        <a href="/docs/quickstart" class="block rounded-sm px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground">Quick start</a>
                        <a href="/docs/installation" class="block rounded-sm px-3 py-2 text-sm hover:bg-accent hover:text-accent-foreground">Installation</a>
                    </NavContent>
                </NavItem>
            </NavList>
        </NavigationMenu>
    </div>
</div>

Plain links sit in the NavList beside the NavItem dropdowns.

Header nav bar

A site header with a logo, the menu and actions. It uses container queries, so it adapts to its own width: on a narrow screen the logo text and extra links drop out and the panel becomes one column. NavContent is 14rem wide by default; a class attribute replaces its classes, which is how the wider two-column panel is made, so keep the positioning classes when you set one.

S
@* Container queries (@@md:, @@2xl:) size the header to its own width; the height leaves room for the open panel. *@
<div class="@@container w-full">
    <div class="h-80 @@md:h-56">
        <header class="flex h-14 items-center gap-1 rounded-lg border border-border bg-background px-2 @@md:gap-2 @@md:px-4">
            <a href="/" class="flex shrink-0 items-center gap-2 font-semibold @@md:mr-2">
                <span class="flex size-6 items-center justify-center rounded-md bg-primary text-xs font-bold text-primary-foreground">S</span>
                <span class="hidden @@md:inline">ShellUI</span>
            </a>
            <NavigationMenu>
                <NavList>
                    <NavItem>
                        <NavTrigger>Components</NavTrigger>
                        <NavContent class="@PanelClass">
                            @foreach (var (title, text, href) in categories)
                            {
                                <a href="@href" class="rounded-sm p-2 hover:bg-accent hover:text-accent-foreground">
                                    <div class="text-sm font-medium">@title</div>
                                    <div class="text-xs text-muted-foreground">@text</div>
                                </a>
                            }
                        </NavContent>
                    </NavItem>
                    <a href="/docs/theming" class="hidden h-10 items-center rounded-md px-4 py-2 text-sm font-medium transition-colors hover:bg-accent hover:text-accent-foreground @@2xl:inline-flex">Theming</a>
                </NavList>
            </NavigationMenu>
            <div class="ml-auto flex shrink-0 items-center gap-2">
                <div class="hidden @@3xs:block @@md:hidden @@2xl:block">
                    <Button Variant="ButtonVariant.Ghost" Size="ButtonSize.Sm">Sign in</Button>
                </div>
                <div class="hidden @@md:block">
                    <Button Size="ButtonSize.Sm">Get started</Button>
                </div>
            </div>
        </header>
    </div>
</div>

@code {
    private const string PanelClass = "absolute -left-9 top-full mt-1 grid w-56 gap-1 rounded-md border border-border bg-popover p-2 shadow-lg @md:left-0 @md:w-80 @md:grid-cols-2";

    private readonly (string Title, string Text, string Href)[] categories =
    [
        ("Form", "Inputs and controls", "/docs/components/form"),
        ("Layout", "Cards, dialogs, sheets", "/docs/components/layout"),
        ("Navigation", "Menus, tabs, breadcrumbs", "/docs/components/navigation"),
        ("Advanced", "Charts, calendar, chat", "/docs/components/advanced"),
    ];
}

API Reference

Parameter Type Default Description
ChildContent RenderFragment — NavList
Parameter Type Default Description
ChildContent RenderFragment — NavItem children
Parameter Type Default Description
ChildContent RenderFragment — NavTrigger + NavContent
ClassName string "" Additional CSS classes
Parameter Type Default Description
ChildContent RenderFragment — Trigger button label
Parameter Type Default Description
ChildContent RenderFragment — Dropdown panel content

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.