NavMenu
JavaScript off: what the HTML and CSS do on their own.
Usage
<AppSidebar>
<NavMenu>
<NavItem Href="/" Icon="Lucide.House">Home</NavItem>
<NavItem Href="/projects" Icon="Lucide.Folder">Projects</NavItem>
<NavItem Href="/inbox" Icon="Lucide.Inbox" Badge="4">Inbox</NavItem>
<NavDivider />
<NavItem Href="/settings" Icon="Lucide.Settings">Settings</NavItem>
</NavMenu>
</AppSidebar>A nav menu is a list of links that marks the one for the current page. It works the same on static and interactive pages, with or without JavaScript: the server works out the current page from the address.
Organizing a sidebar
Use NavLabel to name a section of links, NavGroup to fold some away, NavDivider for a line between sections, and Badge on an item for a count or a label.
A group is a native details element, so it opens and closes with no script. Open starts it open, and ActivePrefix opens it on the pages at or below a path, such as /projects; with the script, a group holding the current page opens itself too.
The current page
Use Match to say how the address must match an item's Href: by default an item is current on its page and the pages below it, and NavLinkMatch.All makes it current on its own page only.
@* Current on /projects and on /projects/42 *@
<NavItem Href="/projects">Projects</NavItem>
@* Current on /reports only *@
<NavItem Href="/reports" Match="NavLinkMatch.All">Reports</NavItem>
@* Current on /inbox, unless Starred is *@
<NavItem Href="/inbox">Inbox</NavItem>
@* Current on /inbox?view=starred *@
<NavItem Href="/inbox?view=starred">Starred</NavItem>A link to the app's root (/) is only ever current on the home page, and a link with a query string only when the query is the same. Of links to one page told apart by the query, as Inbox and Starred are, one is current at a time: the link without a query gives way when one with a query matches, as Dashboard does in the sidebar example when another item is picked.
Badges and counts
Use BadgeVariant.Plain for quiet totals with no fill, as docs and mail sidebars show them; BadgeAccent gives a badge a color of its own, such as Accent.Primary for an unread count, and BadgeStatus a status's color.
Long labels wrap rather than being cut off.
A row of links
Use Orientation="Orientation.Horizontal" for a row of section links, such as a project's pages; when they don't fit, as on a phone, the row scrolls sideways.
For a site's main links in the header, which fold into a menu on phones, use a SiteNav: it takes the same NavItems.
In a landmark
A nav menu is a list, not a landmark: put it in an AppSidebar, which is a nav named "Main", or in a nav element with its own aria-label, as the examples do. Use HiddenFrom or VisibleFrom on an item to show it only on some screens; they hide the whole list item.
Parts
Written inside NavMenu. The API page lists their parameters.
NavItem: one navigation link.NavGroup: a collapsible group of nav items, built on <details>, so it opens and closes with no JavaScript.NavLabel: a small heading that labels the items below it in a NavMenu: a plain list item, since a list holds only items.NavDivider: a line between groups of items in a NavMenu.
Mode support
| Feature | Off | Static | Live |
|---|---|---|---|
| Everything | Yes | Yes | Yes |
Off: JavaScript disabled. Static: a static SSR page with IzzyBlazor's script. Live: an interactive page (Server, WebAssembly or Auto).
Accessibility
- It renders a
ulof links, not a landmark: put it in an AppSidebar (anavnamed "Main") or in anavwith its ownaria-label. - The active item has
aria-current="page"; an item above the current page (MatchPrefix) getsaria-current="true", so screen readers hear one current page. Of links to one page told apart by the query (?view=starred), only one is current. - A
NavGroupis a nativedetails, so Enter and Space open and close it with no script; with script, a group holding the current page opens itself. NavLabelis a plain list item, read as text before the links under it, not a heading or a group name;NavDivideris hidden from screen readers, as a list holds only items.
Parameters
| Prop | Type | Default |
|---|---|---|
OrientationVertical for sidebars (the default), horizontal for header bars. | Orientation | Orientation.Vertical |
ChildContentThe items: NavItem, NavGroup, NavLabel, NavDivider. | RenderFragment? |
Plus 16 item props and 4 common props.
Full APISee also
- AppSidebar: a sidebar that becomes a drawer or panel on small screens.
- SiteNav: header links that fold into a menu on phones.
- Tabs: panels that switch with no script, or links to pages.
- Breadcrumb: the path to the current page.