Sidebar Nav

Free

The reusable half of a dashboard sidebar: grouped items, click-to-expand sub-navigation with an active trail, a collapsed rail and a mobile drawer — with no router dependency and no brand welded in. Bring your own header and footer. Pro adds rail flyouts, search, pinning, tones, floating and inset appearances and a resizable width.

</>sv-sidebar-nav sidebarnavigationshellraildrawermenudashboard
import { SvSidebarNavComponent } from '@styloviz/sidebar-nav';

Demo & usage

Basic usage

Usage example — open the gallery for the full interactive demo.

An interactive demo for this component lives in the gallery.

Open live demo

More examples

With projected chrome

example.htmlAngular
<sv-sidebar-nav [menuGroups]="groups" [activeRoute]="router.url">
  <a slot="header" href="/">Acme</a>
  <span slot="footer">v2.4</span>
</sv-sidebar-nav>

Collapsed rail, no footer

example.htmlAngular
<sv-sidebar-nav [menuGroups]="groups" [collapsed]="true" [showFooter]="false" />

Wiring it to the Angular router

example.htmlAngular
// One provider, once, at the app root. The component never imports the
// router itself — that is what makes it usable in a hybrid app.
provideSvLinkAdapter(() => {
  const router = inject(Router);
  return {
    kind: 'router',
    href: (t) => router.serializeUrl(router.createUrlTree([t].flat())),
    navigate: (t) => { void router.navigateByUrl(`${t}`); return true; },
  };
})

When to use

  • The primary navigation of a dashboard, admin panel or internal tool.
  • You want the rail and the mobile drawer without writing route-sync three times.
  • Your app does not route the way Angular's router does — a hybrid shell, a micro-frontend, a widget embedded in somebody else's page.
  • For a horizontal header, use Mega Menu; for in-page sections, use Anchor. This is the persistent side rail.
  • Part of the App Shell family — Sidebar (shell) · Sidebar Nav (tree): `sv-sidebar` (in `@styloviz/layout`) is the collapsible container of a dashboard shell, and this is the tree you put inside it.

Compare with

  • Bottom Navigation — Bottom Navigation renders the same MenuItem model as a phone app bar of three to five destinations. Feed both the same array and hide each where the other shows.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Item identity & owned state

Restorable state
  • expandedIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
menuGroupsreadonly MenuGroup[][]Grouped navigation items.
activeRoutestring''The path the reader is on, so one item can be marked current. Controlled rather than derived: matching a route is the router's job, and a component that guessed at it would be wrong in a different way in every app. `[activeRoute]="router.url"` is the whole wiring for a routed app.
childKeystring | null'c'URL parameter naming the open sub-item — the same `?c=…` parameter `sv-sidebar` uses. Read through `SvNavLocation`, so it is inert until the app provides one. `null` turns sub-item tracking off.
activeChildIdstring | nullnullPin the open sub-item, ignoring the URL. For a host that keeps this in its own state rather than in the address.
collapsedboolean (two-way)falseIcon-only rail. Two-way via `[(collapsed)]`.
mobileOpenboolean (two-way)falseMobile drawer open. Two-way via `[(mobileOpen)]`.
mobileBreakpointnumber1024Viewport width below which the sidebar becomes an off-canvas drawer driven by `mobileOpen`. Set to `0` to keep it docked at every size — e.g. when it is embedded in a panel rather than used as the page's shell.
ariaLabelstring'Main navigation'Accessible name of the `<nav>` landmark. A page with two of these — a primary sidebar and a secondary panel — needs them told apart.
showHeaderbooleantrueRender the header / footer slots at all. A rail with no chrome is a common shape and an empty bordered box is not.
showFooterbooleantrueRender the footer area holding the `[slot=footer]` content and, outside the mobile drawer, the collapse toggle.
surfaceIdstring | nullnullNames this sidebar in the shared navigation-analytics stream. Ignored unless `provideSvNavTelemetry()` is wired up.
customClassstring''Additional CSS classes on the `<aside>`.
expandModeSidebarNavExpandMode'multiple'Whether opening one section closes the others.
expandedIdsreadonly string[] (two-way)[]Keys (`item.id`, else the route) of the items whose sub-pages are open, and `<item key>::<sub-item id>` for an open third level. The section the reader is inside opens on its own, and closes again when they leave unless they opened it themselves. Two-way.
collapsedGroupsreadonly string[] (two-way)[]Keys (`group.id`, else its label) of `collapsible` groups folded away. Two-way.
activeStyleSidebarNavActiveStyle'fill'The active row's look.
badgeVariantSidebarNavBadgeVariant'pill'How badges are drawn.
densitySidebarNavDensity'comfortable'Row height.
labelsPartial<SvSidebarNavLabels>{}Every string the sidebar renders.
scrollFadeSidebarNavScrollFade'gradient'Fades at the list's edges while there is more to scroll. `'gradient'` fades to the sidebar's surface (`--sv-sa-fade` to change it); `'shadow'` suits a tinted or translucent sidebar.
drawerModeSidebarNavDrawerMode'overlay'The drawer below `mobileBreakpoint`: over the page, or pushing it aside.
swipeToClosebooleantrueSwipe the open drawer toward its edge to close it (touch and pen).
edgeSwipebooleanfalseSwipe in from the start edge of the screen to open the drawer.

Outputs

EventPayload typeDescription
itemSelectedSidebarNavSelectionSomething was picked. Carries the group and, for a sub-item, the child — a host closing a drawer needs the event, and a host doing its own analytics needs to know *which* thing was clicked, not just that one was.
mobileClosevoidThe drawer should close. Emitted alongside `mobileOpen` being set to `false`, for a host that has its own shell state to keep in step.
toggleCollapsebooleanThe rail toggle was pressed. `collapsed` is already flipped.
collapsedChangebooleanEmits the new `collapsed` whenever it changes — the output half of `[(collapsed)]`.
mobileOpenChangebooleanEmits the new `mobileOpen` whenever it changes — the output half of `[(mobileOpen)]`.
expandedIdsChangereadonly string[]Emits the new `expandedIds` whenever it changes — the output half of `[(expandedIds)]`.
collapsedGroupsChangereadonly string[]Emits the new `collapsedGroups` whenever it changes — the output half of `[(collapsedGroups)]`.

<sv-sidebar-nav-pro>

Also in this family — SvSidebarNavProComponent from @styloviz-pro/layout.

Async states

None — this component has nothing to load, so it has no loading, empty or error state to drive.

Item identity & owned state

Restorable state
  • expandedIds

Bind these to put a saved view back — the open sections, the hidden columns, the selected rows — and read their Change events to store what the user does.

Inputs

NameTypeDefaultDescription
menuGroupsreadonly MenuGroup[][]Grouped navigation items.
activeRoutestring''The path the reader is on.
childKeystring | null'c'URL parameter naming the open sub-item.
activeChildIdstring | nullnullPin the open sub-item, ignoring the URL.
collapsedboolean (two-way)falseIcon-only rail. Two-way.
mobileOpenboolean (two-way)falseMobile drawer open. Two-way.
mobileBreakpointnumber1024Width below which the sidebar becomes a drawer; 0 keeps it docked.
ariaLabelstring'Main navigation'The `<nav>` landmark's name.
showHeaderbooleantrueRender the header area.
showFooterbooleantrueRender the footer area.
expandModeSidebarNavExpandMode'multiple'Whether opening one section closes the others.
expandedIdsreadonly string[] (two-way)[]Keys of the items whose sub-pages are open. Two-way.
collapsedGroupsreadonly string[] (two-way)[]Keys of `collapsible` groups folded away. Two-way.
activeStyleSidebarNavActiveStyle'fill'The active row's look.
badgeVariantSidebarNavBadgeVariant'pill'How badges are drawn.
densitySidebarNavDensity'comfortable'Row height.
labelsPartial<SvSidebarNavLabels>{}The free sidebar's strings.
scrollFadeSidebarNavScrollFade'gradient'Fades at the list's edges. `glass` switches a gradient to a shadow.
drawerModeSidebarNavDrawerMode'overlay'The drawer: over the page, or pushing it aside.
swipeToClosebooleantrueSwipe the open drawer toward its edge to close it.
edgeSwipebooleanfalseSwipe in from the screen's start edge to open the drawer.
searchablebooleanfalseA search box above the list.
querystring (two-way)''The search text. Two-way.
pinnedreadonly string[] (two-way)[]Keys (`item.id`, else the route) of pinned items, listed above the rest. Two-way.
pinnablebooleanfalseA pin button at the end of every row, so the reader pins and unpins from the sidebar itself.
appearanceSidebarNavProAppearance'docked'Docked, a floating card, or inset on a tinted shell.
toneSidebarNavProTone'auto'Follow the app's theme, or pin the sidebar light or dark.
glassbooleanfalseFrosted glass, for a sidebar over media — a map, a video, a photo hero. Only there: over a flat page the blur is invisible and costs a GPU layer every scroll frame.
resizablebooleanfalseA drag handle on the inline-end edge.
widthnumber (two-way)256The expanded width in px, with `resizable`. Two-way.
minWidthnumber208The narrowest a reader can drag it, in px.
maxWidthnumber400The widest a reader can drag it, in px.
flyoutsbooleantrueIn the rail, show a section's sub-pages in a flyout.
proLabelsPartial<SvSidebarNavProLabels>{}The strings this component adds.

Outputs

EventPayload typeDescription
itemSelectedSidebarNavSelectionSomething was picked.
mobileClosevoidThe drawer should close.
toggleCollapsebooleanThe rail toggle was pressed.
collapsedChangebooleanEmits the new `collapsed` whenever it changes — the output half of `[(collapsed)]`.
mobileOpenChangebooleanEmits the new `mobileOpen` whenever it changes — the output half of `[(mobileOpen)]`.
expandedIdsChangereadonly string[]Emits the new `expandedIds` whenever it changes — the output half of `[(expandedIds)]`.
collapsedGroupsChangereadonly string[]Emits the new `collapsedGroups` whenever it changes — the output half of `[(collapsedGroups)]`.
queryChangestringEmits the new `query` whenever it changes — the output half of `[(query)]`.
pinnedChangereadonly string[]Emits the new `pinned` whenever it changes — the output half of `[(pinned)]`.
widthChangenumberEmits the new `width` whenever it changes — the output half of `[(width)]`.

Customization & theming

  • Expanded, collapsed rail and mobile drawer out of one model. The model and its route matcher (`svSidebarActiveItem`, `svSidebarRouteActive`) are exported, so your own navigation surfaces can reuse them rather than re-implementing route sync.
  • Badges per item, with four tints; sub-navigation groups per item.
  • `childKey` names the URL parameter that tracks the open sub-item, read through `SvNavLocation`; `activeChildId` pins it from host state instead.
  • `showHeader` / `showFooter` remove the chrome boxes entirely for a bare rail.
  • Items with children expand on click (chevron + `aria-expanded`), the active item's parents open by themselves, and `expandMode` (`multiple` · `single`) with `[(expandedIds)]` and `[(collapsedGroups)]` holds the state.
  • `activeStyle` (`fill` · `bar`), `badgeVariant` (`pill` · `count` · `dot`), `density` (`comfortable` · `compact`), `scrollFade` (`gradient` · `shadow` · `none`) and translatable `labels`; the mobile drawer has `drawerMode` (`overlay` · `push`), `swipeToClose` and `edgeSwipe`.
  • Pro (`sv-sidebar-nav-pro`, in `@styloviz-pro/layout`): rail `flyouts`, a `searchable` filter with `[(query)]`, `pinnable` items with `[(pinned)]`, `tone` (`auto` · `light` · `dark` · `dual`), `appearance` (`docked` · `floating` · `inset`), `glass`, and a `resizable` `[(width)]` between `minWidth` and `maxWidth`.

Best practices

  • Do: Bind `activeRoute` to your router's current URL. The component deliberately does not derive it: matching a route is the router's hardest job, and a component that guessed would be wrong differently in every app.
  • Do: Project your own header and footer. The component ships no logo, no wordmark and no resource links, so it fits any product.
  • Tip: Give the `<nav>` a distinct `ariaLabel` when a page has two of them. A primary sidebar and a secondary settings panel are two landmarks, and a screen-reader user needs them told apart.
  • Don't: Don't keep sub-navigation open in the collapsed rail. There is no room for it, and a tooltip is not a sub-menu — on `sv-sidebar-nav-pro`, a railed item with children opens a flyout menu instead (`flyouts`, on by default).

Accessibility

  • Every destination is a real `<a href>`, so middle-click, ⌘-click and "copy link address" work — which they cannot when a router directive owns the element.
  • The current item carries `aria-current="page"`, as does the open sub-item.
  • The collapse control is a real `<button>` with `aria-expanded` and a label that says which way it will go.
  • A modified click is never intercepted: that gesture means "open this somewhere else".
  • The `<nav>` landmark takes its accessible name from `ariaLabel`.

Feedback on Sidebar Nav

Spotted a gap in this page, or something that didn't work as described? Comments are GitHub Discussions in the public styloviz/community repo, so posting needs a GitHub account.

Loads giscus.app and GitHub — nothing is fetched until you click.