Menu
JavaScript off: what the HTML and CSS do on their own.
Usage
<Menu Label="Project" StartIcon="Lucide.Folder">
@* A link, on any page. *@
<MenuItem Href="settings" Icon="Lucide.Settings">Settings</MenuItem>
@* Posts the form the menu is in, on any page. *@
<MenuItem Submit Name="intent" Value="archive" Icon="Lucide.Archive">Archive</MenuItem>
@* C# on click, on interactive pages. *@
<MenuItem OnClick="Duplicate" Icon="Lucide.Copy">Duplicate</MenuItem>
</Menu>Links, posts and actions
Give each MenuItem an Href to go somewhere, Submit to post the form the menu is in, or OnClick to run C# on interactive pages. Links and posts work on static pages, with JavaScript off too.
A submit item posts its Name and Value, so one form tells its items apart. FormAction posts to another address, and Form names a form the menu isn't in. Disabled shows an item that can't be chosen.
Groups, shortcuts and colors
Use MenuGroup for a labeled section and MenuDivider for a line between items. Icon adds an icon, Shortcut shows a key, and Accent="Accent.Danger" marks an item that destroys something.
A shortcut is only shown: the app handles the keys.
Your own trigger
Use Trigger for a button of your own, such as an IconButton, and give it the menu's attributes with @attributes="context". Placement sets where the menu opens.
The panel fits its items, from 10rem to 24rem wide; PanelWidth sets a width of your own. Without a Trigger, Label, StartIcon, Accent, Variant and Size style the default button.
Checked items
Use a MenuRadioGroup with a QueryKey for options kept in the address, such as a sort, and Checked with an Href for an on/off item. Both are links, so they work on static pages.
On an interactive page, @bind-Value on the group and @bind-Checked on an item keep them in C# instead. Name on the group makes its options submit buttons that post with a form, and KeepOpen on an item leaves the menu open, to tick several in a row.
Submenus
Use MenuSub for an item that opens another menu beside it. Choosing an item in it closes the whole menu.
Parts
Written inside Menu. The API page lists their parameters.
MenuItem: one entry in a Menu.MenuGroup: a labeled section of a Menu.MenuDivider: a line between groups of items in a Menu.MenuRadioGroup: a set of menu options where one is chosen (menuitemradio), each a MenuItem with a Value.MenuSub: a submenu: an item that opens a second menu beside it.
Mode support
| Feature | Off | Static | Live |
|---|---|---|---|
| Everything | Partly | Yes | Yes |
Off: JavaScript disabled. Static: a static SSR page with IzzyBlazor's script. Live: an interactive page (Server, WebAssembly or Auto). With JavaScript off, the menu opens and closes, but arrow keys and type-ahead don't move between items.
Accessibility
- With script, it's a
menunamed by its trigger, withmenuitem,menuitemcheckboxandmenuitemradioitems (aria-checked); a MenuGroup is agroupnamed by itsLabel. - Opening it focuses the first item; Down and Up on the trigger open it at the first or last. Escape closes it, and focus goes back to the trigger.
- Down and Up move through the items and wrap, Home and End go to the ends, typing jumps to the next item starting with those letters, and Tab closes the menu. Disabled items are skipped.
- Right opens a MenuSub and focuses its first item; Left closes it (the other way round on right-to-left pages).
- With JavaScript off, items are plain links and buttons with no menu roles; a checked one has
aria-pressed(buttons) oraria-current(links). - A custom
Triggerneeds a name of its own, such as an IconButton'sLabel. AShortcutis display only: the app handles the keys.
Parameters
| Prop | Type | Default |
|---|---|---|
LabelThe default trigger's text. | string? | |
AccentThe default trigger's color. | Accent | Accent.Neutral |
VariantThe default trigger's weight. | ButtonVariant | ButtonVariant.Outline |
SizeThe default trigger's size. | ControlSize | ControlSize.Md |
StartIconAn icon before the default trigger's text. | IconData? | |
TriggerA custom trigger in place of the default button. | RenderFragment<IReadOnlyDictionary<string, object>>? | |
PlacementWhere the menu opens. | Placement | Placement.BottomStart |
PanelWidthThe width of the menu panel, such as Length.Rem(16) for a column of long labels. | Length? | computed |
ChildContentThe MenuItems, MenuGroups and MenuDividers. | RenderFragment? | |
@bind-OpenWhether it is open. | bool | false |
IdThe element id. | string? |
Plus 16 item props and 4 common props.
Full APISee also
- Popover: non-modal content beside a trigger.
- NavMenu: a list of links that marks the current page.
- ButtonGroup: joined or spaced buttons with shared defaults.
- IconButton: a square button with a required label.
- Troubleshooting: OnClick does nothing on a static page.