Menubar

A horizontal bar of menus, like a desktop application's menu bar.

Menubar holds a row of menus. In v0.4 it can be composed from parts: MenubarMenu, MenubarTrigger, MenubarContent, MenubarItem and MenubarSeparator.

Installation

bash
shellui add menubar

This also installs the parts.

Usage

Composed from parts

Each MenubarMenu pairs a MenubarTrigger with a MenubarContent. A MenubarItem inside the content runs OnClick and closes the menu. A MenubarItem placed directly in the bar is a plain button.

Last action: none

<Menubar>
    <MenubarMenu>
        <MenubarTrigger>File</MenubarTrigger>
        <MenubarContent>
            <MenubarItem OnClick="@(() => last = "New file")">New file</MenubarItem>
            <MenubarItem OnClick="@(() => last = "Open")">Open...</MenubarItem>
            <MenubarSeparator />
            <MenubarItem OnClick="@(() => last = "Save")">Save</MenubarItem>
            <MenubarItem Disabled="true">Save as...</MenubarItem>
        </MenubarContent>
    </MenubarMenu>
    <MenubarMenu>
        <MenubarTrigger>Edit</MenubarTrigger>
        <MenubarContent>
            <MenubarItem OnClick="@(() => last = "Undo")">Undo</MenubarItem>
            <MenubarItem OnClick="@(() => last = "Redo")">Redo</MenubarItem>
        </MenubarContent>
    </MenubarMenu>
    <MenubarItem OnClick="@(() => last = "Help")">Help</MenubarItem>
</Menubar>

<p class="mt-3 text-sm text-muted-foreground">Last action: @last</p>

@code {
    private string last = "none";
}

With Title

A MenubarItem with a Title is a dropdown by itself: the title is the trigger and the child content is the menu. This is the 0.3 API, and it still works.

<Menubar>
    <MenubarItem Title="View">
        <button type="button" class="block w-full rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent">Zoom in</button>
        <button type="button" class="block w-full rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent">Zoom out</button>
    </MenubarItem>
    <MenubarItem Title="Window">
        <button type="button" class="block w-full rounded-sm px-2 py-1.5 text-left text-sm hover:bg-accent">Minimize</button>
    </MenubarItem>
</Menubar>

API Reference

Parameter Type Default Description
ChildContent RenderFragment? null Menus and items
Class string? null Additional CSS classes
Parameter Type Default Description
Title string "" Set for the dropdown form; leave empty for a clickable item
OnClick EventCallback<MouseEventArgs> - Fires when a clickable item is chosen
Disabled bool false Disables a clickable item
ChildContent RenderFragment? null The item label, or the dropdown's content when Title is set
Class string? null Additional CSS classes

Parts

Component Purpose
MenubarMenu One menu; holds a trigger and its content
MenubarTrigger The button in the bar that opens the menu
MenubarContent The panel shown while the menu is open
MenubarSeparator A divider between items

Each part takes ChildContent and Class. ClassName on Menubar and MenubarItem still works but is deprecated; use Class.

Accessibility

  • Triggers and items are native buttons, reachable with Tab and activated with Enter or Space
  • data-state on the trigger is open or closed
  • Clicking outside an open menu closes it

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.