The sidebar is a family of nine components. NvSidebar
is the frame, and the other eight go inside it. This page shows what each part is for and how to
place the sidebar in a page. The other chapters cover one topic each:
- The active page: how
activePathmarks the current item, and how to connect it to a router. - Collapsing and resizing: the icon rail, the
openbinding and the resize handle. - Navigation that changes at runtime: menus that follow permissions or data from a server.
The parts#
| Component | What it is for |
|---|---|
NvSidebar | The frame. It holds the mode (type, open), the current route (activePath) and the width. |
NvSidebarlogo | Logo and product name at the top. It switches to a compact logo when the sidebar collapses. |
NvSidebarheader | Optional area below the logo, for a search field or a workspace switcher. |
NvSidebarcontent | The navigation. This is the only part that scrolls. |
NvSidebargroup | A set of items with an optional label. |
NvSidebarnavitem | One destination, or a parent that opens sub-items. |
NvSidebarnavsubitem | A destination inside a parent item. |
NvSidebardivider | A line between groups or sections. |
NvSidebarfooter | Stays at the bottom, below the scrolling navigation. Use it for the user, settings or help. |
Only NvSidebar and the items you need are required. Leave out the logo,
header, groups, dividers or footer when the application has no use for them.
Default source
Items and their links#
Every item wraps a link that you write. It can be a plain <a> or your
router's link component, as long as it renders an <a> with an href. The
sidebar never navigates on its own. It does two things with your link:
- A click anywhere on the row counts as a click on the link, so the icon and the padding are part of the target.
- The link's
hrefis compared with the sidebar'sactivePathto mark the current page. See The active page.
Add an icon to every top-level item. A collapsed sidebar shows nothing
else.
Icons are NvIcon.NameEnum values: the icon's name without hyphens, so
chart-bar is Icon="NvIcon.NameEnum.chartbar".
Sub-items#
Set collapsible on an item and put sub-items
(NvSidebarnavsubitem) inside it.
The item's own link goes in ChildContent, the sub-items in SubitemsSlot.
<NvSidebarnavitem
Icon="NvIcon.NameEnum.folder"
Collapsible="true"
Open="true">
<ChildContent><a href="projects">Projects</a></ChildContent>
<SubitemsSlot>
<NvSidebarnavsubitem>
<a href="projects/aurora">Aurora</a>
</NvSidebarnavsubitem>
<NvSidebarnavsubitem>
<a href="projects/atlas">Atlas</a>
</NvSidebarnavsubitem>
</SubitemsSlot>
</NvSidebarnavitem>
In an expanded sidebar, clicking a collapsible item opens or closes its
sub-menu and does not follow the item's own link. Use a <span> instead of a
link when the parent is only a heading. open holds the state and can be set
from your code. The sub-menu needs collapsible: without it the sub-items
are not shown.
Notifications and trailing content#
notificationCount on an item shows a count at the end of the row, and on the
icon when the sidebar is collapsed. A count of 0 shows nothing. The look
of all counts is set once on the sidebar, with notificationIntention
(brand or neutral) and notificationEmphasis (high or low).
Items and sub-items also have a trailing slot for a tag, a shortcut hint or
an icon at the end of the row.
<TrailingSlot><span>New</span></TrailingSlot>
Place it in the page#
The sidebar is as tall as the viewport and takes its width from the theme: 312 px expanded and 80 px collapsed. Put it in a row next to the main area and let the main area scroll:
In MainLayout.razor, the sidebar sits next to @Body:
@inherits LayoutComponentBase
<div class="flex h-screen">
<NvSidebar>…</NvSidebar>
<main class="min-w-0 flex-1 overflow-auto">@Body</main>
</div>
Inside a smaller container, give the sidebar a height of its own, for example
class="h-full". The examples on these pages do the same to fit their
preview.
The design does not define a mobile layout. On small screens, choose a navigation pattern in your application, such as showing the sidebar in a drawer.