Sidebar Navigation
The <smart-sidebar-navigation> component renders a full-height application sidebar with optional logo, vertical navigation groups, expandable sub-sections, and a profile footer. It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract SidebarNavigationBaseComponent defines the shared API — options (ISidebarNavOptions), cssClass (alias class), and outputs itemClick and itemToggle. SidebarNavigationStandardComponent is a barebones placeholder using native <nav>, <ul>, <li>, <a>, <button> elements and <img> for logo/avatar. SidebarNavigationComponent is the public wrapper that renders SidebarNavigationStandardComponent by default and accepts a custom replacement via SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN.
Usage
<smart-sidebar-navigation
[options]="options"
(itemClick)="onItemClick($event)"
(itemToggle)="onItemToggle($event)"
/>
@if (activeItem()) {
<p>Active item: {{ activeItem() }}</p>
}
@if (expandedItem()) {
<p>Expanded section: {{ expandedItem() }}</p>
}
The preview renders the code above in an application that registers every preset (provideSmartPresets(), see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Components
SidebarNavigationComponent (<smart-sidebar-navigation>)
Main wrapper. Delegates to SidebarNavigationStandardComponent by default. When SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it the options and class inputs. Re-emits itemClick and itemToggle of whichever implementation renders. There is no preset for this component.
SidebarNavigationStandardComponent (<smart-sidebar-navigation-standard>)
Barebones placeholder using native HTML. Renders an outer wrapper with cssClass, an optional <div class="sidebar-logo"> (logo.tpl when set; otherwise <img class="sidebar-logo-img"> from logo.url plus a second .sidebar-logo-img-dark image from logo.urlDark, both with logo.alt, wrapped in a plain <a href> when logo.href is set), a <nav class="sidebar-navigation"> (with aria-label from options.ariaLabel or default "Sidebar"), and a <ul> of groups (options.items as a first, untitled group, then options.groups). Each group renders an optional <div class="group-title"> and a <ul> of items.
Items render in three forms.
<a class="item-link">(whenhrefis provided; a plain<a href>)<button class="item-button">(when there is nohref; a click emitsitemClick)<button class="item-toggle">followed by<ul class="children">(whenexpandable === true; a click emitsitemToggle)
Links and buttons get the current class and aria-current="page" when item.current === true, and show iconTpl (or, without it, initial, e.g. a team letter), label and badge. An expandable toggle shows only iconTpl, label and a chevron: its initial, badge and current are not rendered. The toggle keeps a local expanded state per item id, starting from item.expanded. Children render as .child-link / .child-button with their label, href and current only: their iconTpl, initial, badge, expandable and children are not rendered (one nesting level).
When options.profile is present, renders a <li class="profile"> at the bottom containing <a class="profile-link"> (to profile.href, '#' by default) with <img class="profile-avatar"> (avatarUrl, avatarAlt), an optional .sr-only text (srOnlyText) and the .profile-name (name).
SidebarNavigationBaseComponent (abstract)
Abstract base directive. Exposes:
options: InputSignal<ISidebarNavOptions | undefined>cssClass: InputSignal<string>(aliasclass)itemClick: OutputEmitterRef<ISidebarNavItemClick>itemToggle: OutputEmitterRef<ISidebarNavItemToggle>- protected
resolvedGroups: Signal<ISidebarNavGroup[]>— normalizesoptions.itemsinto a single-group structure alongsideoptions.groups - protected
expandedOverrides: WritableSignal<Record<string, boolean>>— internal toggle state per item id - protected
isExpanded(item)/toggleExpanded(item)— helpers for managing expandable items
ISidebarNavItemClick = { itemId: string }. ISidebarNavItemToggle = { itemId: string; expanded: boolean }.
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<ISidebarNavOptions | undefined> | - | Sidebar navigation configuration |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
Outputs
| Output | Type | Description |
|---|---|---|
itemClick | OutputEmitterRef<ISidebarNavItemClick> | Emitted when a button-type nav item or child is clicked |
itemToggle | OutputEmitterRef<ISidebarNavItemToggle> | Emitted when an expandable item is toggled |
ISidebarNavOptions
When both items and groups are provided, items is rendered first as a leading, untitled group.
| Field | Type | Default | Description |
|---|---|---|---|
ariaLabel | string | 'Sidebar' | Accessible name of the <nav>. |
logo | ISidebarNavLogo | - | The brand at the top. |
items | ISidebarNavItem[] | - | The first, untitled group of items. |
groups | ISidebarNavGroup[] | - | Further groups, each with an optional title. |
profile | ISidebarNavProfile | - | A profile link at the bottom. |
layout | SmartSidebarNavLayout | - | Not read by the built-in implementations; available to a custom implementation. |
SmartSidebarNavLayout is 'light' | 'dark' | 'with-expandable-sections' | 'with-secondary-navigation' | 'brand'.
ISidebarNavItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as itemId. |
label | string | - | Item text. |
href | string | - | Renders a plain <a href> (no itemClick). |
current | boolean | - | Marks the current page (current class, aria-current="page"); not on toggles. |
badge | string | number | - | A count or text badge; not on toggles and children. |
iconTpl | TemplateRef<unknown> | - | Item icon; not on children. |
initial | string | - | A letter shown instead of an icon (e.g. for teams); not on toggles and children. |
expandable | boolean | - | Makes the item a toggle for its children (top-level items only). |
expanded | boolean | false | Initial expanded state of an expandable item. |
children | ISidebarNavItem[] | - | Nested items of an expandable item; one level, rendered with label, href, current. |
ISidebarNavGroup
| Field | Type | Default | Description |
|---|---|---|---|
id | string | - | Tracking key of the group. |
title | string | - | Group heading (.group-title). |
items | ISidebarNavItem[] | required | The group's items. |
ISidebarNavLogo
| Field | Type | Default | Description |
|---|---|---|---|
url | string | - | Logo image. |
urlDark | string | - | A second image with the sidebar-logo-img-dark class hook. |
alt | string | '' | Alt text of both images. |
href | string | - | Wraps the images in a plain <a href>. |
tpl | TemplateRef<unknown> | - | The logo as a template; wins over the images. |
ISidebarNavProfile
| Field | Type | Default | Description |
|---|---|---|---|
name | string | - | User name. |
avatarUrl | string | - | Avatar image. |
avatarAlt | string | '' | Alt text of the avatar. |
href | string | '#' | Profile link. |
srOnlyText | string | - | Text for screen readers (e.g. "Your profile"). |
ISidebarNavItemClick and ISidebarNavItemToggle
| Type | Field | Type | Description |
|---|---|---|---|
ISidebarNavItemClick | itemId | string | The id of the clicked item. |
ISidebarNavItemToggle | itemId | string | The id of the toggled item. |
ISidebarNavItemToggle | expanded | boolean | The new expanded state. |
SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN
Provide a component class extending SidebarNavigationBaseComponent under SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN; every <smart-sidebar-navigation> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
ISidebarNavOptions,
SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN,
SidebarNavigationBaseComponent,
SidebarNavigationComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-sidebar-navigation',
template: `
<nav
[class]="containerClasses()"
[attr.aria-label]="options()?.ariaLabel ?? 'Sidebar'"
>
<!--
resolvedGroups() is the protected helper of the base class: it merges
the flat items list and the named groups into a single list.
-->
@for (group of resolvedGroups(); track $index) {
<div class="docs-sidebar-navigation__group">
@if (group.title) {
<p class="docs-sidebar-navigation__group-title">
{{ group.title }}
</p>
}
<ul>
@for (item of group.items; track item.id) {
<li>
@if (item.expandable) {
<button
type="button"
class="docs-sidebar-navigation__toggle"
[attr.aria-expanded]="isExpanded(item)"
(click)="toggleExpanded(item)"
>
{{ item.label }}
</button>
@if (isExpanded(item)) {
<ul class="docs-sidebar-navigation__children">
@for (child of item.children ?? []; track child.id) {
<li>
<a
class="docs-sidebar-navigation__child-link"
[href]="child.href"
(click)="itemClick.emit({ itemId: child.id })"
>
{{ child.label }}
</a>
</li>
}
</ul>
}
} @else {
<a
class="docs-sidebar-navigation__link"
[href]="item.href"
[attr.aria-current]="item.current ? 'page' : null"
(click)="itemClick.emit({ itemId: item.id })"
>
@if (item.initial) {
<span class="docs-sidebar-navigation__initial">
{{ item.initial }}
</span>
}
<span>{{ item.label }}</span>
@if (item.badge !== undefined) {
<span class="docs-sidebar-navigation__badge">
{{ item.badge }}
</span>
}
</a>
}
</li>
}
</ul>
</div>
}
@if (options()?.profile) {
<a
class="docs-sidebar-navigation__profile"
[href]="options()?.profile?.href"
>
{{ options()?.profile?.name }}
</a>
}
</nav>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomSidebarNavigationComponent extends SidebarNavigationBaseComponent {
// `layout` is not read by the built-in implementations: a custom one decides
// what it means, here a modifier class.
readonly containerClasses = computed(() => {
const classes = [
'docs-sidebar-navigation',
`docs-sidebar-navigation--${this.options()?.layout ?? 'light'}`,
];
const extra = this.cssClass();
if (extra) classes.push(extra);
return classes.join(' ');
});
}
@Component({
selector: 'docs-sidebar-navigation-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [SidebarNavigationComponent],
// The token swaps the standard navigation for the custom one everywhere
// below this component, so consumers keep writing
// `<smart-sidebar-navigation>`.
providers: [
{
provide: SIDEBAR_NAVIGATION_STANDARD_COMPONENT_TOKEN,
useValue: CustomSidebarNavigationComponent,
},
],
// The wrapper re-emits the custom component's itemClick and itemToggle.
template: `
<smart-sidebar-navigation
[options]="options"
(itemClick)="activeItem.set($event.itemId)"
/>
@if (activeItem()) {
<p>Active item: {{ activeItem() }}</p>
}
`,
})
export class SidebarNavigationCustomExampleComponent {
readonly activeItem = signal<string | null>(null);
readonly options: ISidebarNavOptions = {
layout: 'light',
ariaLabel: 'Sidebar',
items: [
{ id: 'dashboard', label: 'Dashboard', href: '#', current: true },
{ id: 'team', label: 'Team', href: '#', badge: 5 },
{ id: 'projects', label: 'Projects', href: '#', badge: 12 },
{
id: 'teams',
label: 'Teams',
expandable: true,
children: [
{ id: 'engineering', label: 'Engineering', href: '#' },
{ id: 'human-resources', label: 'Human Resources', href: '#' },
],
},
],
groups: [
{
id: 'your-teams',
title: 'Your teams',
items: [
{
id: 'engineering-team',
label: 'Engineering',
initial: 'E',
href: '#',
},
{ id: 'marketing-team', label: 'Marketing', initial: 'M', href: '#' },
],
},
],
profile: { name: 'Tom Cook', href: '#', srOnlyText: 'Your profile' },
};
}
Source
The component lives in packages/shared/angular/src/lib/components/sidebar-navigation and is documented for Claude Code by the angular-components-sidebar-navigation skill.
SmartSidebarNavigation is the navigation column of an application: an optional logo (light and dark image, or a tpl node), items (an untitled first group) followed by titled groups, and a profile link at the bottom. Items show an icon or an initial and a badge; an expandable item opens its children (reported through onItemToggle({ itemId, expanded })). Items with an internal href render through the navigation adapter's linkComponent when one is set; items without href are buttons reported through onItemClick({ itemId }). There is no preset; the standard rendering is semantic markup with class hooks.
Usage
import { useState } from 'react';
import {
ISidebarNavItemClick,
ISidebarNavItemToggle,
ISidebarNavOptions,
SmartSidebarNavigation,
} from '@smartsoft001/react';
const options: ISidebarNavOptions = {
ariaLabel: 'Main',
items: [
{ id: 'dashboard', label: 'Dashboard', current: true },
{ id: 'projects', label: 'Projects', badge: 5 },
{
id: 'reports',
label: 'Reports',
expandable: true,
children: [
{ id: 'revenue', label: 'Revenue' },
{ id: 'churn', label: 'Churn' },
],
},
],
profile: { name: 'Anna Kowalska', href: '/profile' },
};
export function SidebarNavigationUsageExample() {
const [activeItem, setActiveItem] = useState<string | null>(null);
const [expandedItem, setExpandedItem] = useState<string | null>(null);
const onItemClick = ({ itemId }: ISidebarNavItemClick) =>
setActiveItem(itemId);
const onItemToggle = ({ itemId, expanded }: ISidebarNavItemToggle) =>
setExpandedItem(expanded ? itemId : null);
return (
<>
<SmartSidebarNavigation
options={options}
onItemClick={onItemClick}
onItemToggle={onItemToggle}
/>
{activeItem && <p>Active item: {activeItem}</p>}
{expandedItem && <p>Expanded section: {expandedItem}</p>}
</>
);
}
The preview renders the code above in an application that registers every preset (SMART_PRESET_COMPONENTS on SmartProvider, see Installation) and the English translations; without the presets, a component that has one renders its standard implementation instead, for most components unstyled markup.
Exports
All from @smartsoft001/react.
| Export | Kind | What it is |
|---|---|---|
SmartSidebarNavigation | component | Renders the implementation registered as components['sidebar-navigation'] on SmartProvider, SmartSidebarNavigationStandard by default. |
SmartSidebarNavigationStandard | component | The default sidebar navigation rendering. |
useSidebarNavigation | hook | The behaviour every sidebar navigation variant shares: options.items normalised into a first, untitled group followed by options.groups; the expanded state of the expandable items, starting from item.expanded and flipped by toggleExpanded (reported through onItemToggle); and the item click. |
Props and Types
SmartSidebarNavigationProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | ISidebarNavOptions | — | Logo, items, groups and profile. |
className? | string | — | Classes on the root element. |
onItemClick? | (event: ISidebarNavItemClick) => void | — | A click on an item (or child) without href. |
onItemToggle? | (event: ISidebarNavItemToggle) => void | — | An expandable item was opened or closed. |
ISidebarNavOptions
| Field | Type | Default | Description |
|---|---|---|---|
layout? | SmartSidebarNavLayout | — | Not read by the built-in implementations; available to a custom implementation. |
ariaLabel? | string | 'Sidebar' | Accessible name of the nav. |
logo? | ISidebarNavLogo | — | The brand at the top. |
items? | ISidebarNavItem[] | — | The first, untitled group of items. |
groups? | ISidebarNavGroup[] | — | Further groups, each with a title. |
profile? | ISidebarNavProfile | — | A profile link at the bottom. |
ISidebarNavItemClick
| Field | Type | Default | Description |
|---|---|---|---|
itemId | string | required | The id of the clicked item. |
ISidebarNavItemToggle
| Field | Type | Default | Description |
|---|---|---|---|
itemId | string | required | The id of the toggled item. |
expanded | boolean | required | The new expanded state. |
ISidebarNavLogo
| Field | Type | Default | Description |
|---|---|---|---|
url? | string | — | Logo image. |
urlDark? | string | — | A second image with the sidebar-logo-img-dark class hook (for dark mode). |
alt? | string | '' | Alt text of both images. |
href? | string | — | Wraps the images in a link (through the navigation adapter for internal paths). |
tpl? | ReactNode | — | The logo as a node; wins over the images. |
ISidebarNavItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as itemId. |
label? | string | — | Item text. |
href? | string | — | Renders a link (through the navigation adapter for internal paths). |
current? | boolean | — | Marks the current page (current class, aria-current="page"); not on toggles. |
badge? | string | number | — | A count or text badge; not on toggles and children. |
iconTpl? | ReactNode | — | Item icon; not on children. |
initial? | string | — | A letter shown instead of an icon (e.g. for teams); not on toggles and children. |
expandable? | boolean | — | Makes the item a toggle for its children (top-level items only). |
expanded? | boolean | false | Initial expanded state of an expandable item. |
children? | ISidebarNavItem[] | — | Nested items of an expandable item; one level, rendered with label, href, current. |
ISidebarNavGroup
| Field | Type | Default | Description |
|---|---|---|---|
id? | string | — | Key of the group. |
title? | string | — | Group heading. |
items | ISidebarNavItem[] | required | The group's items. |
ISidebarNavProfile
| Field | Type | Default | Description |
|---|---|---|---|
name? | string | — | User name. |
avatarUrl? | string | — | Avatar image. |
avatarAlt? | string | '' | Alt text of the avatar. |
href? | string | '#' | Profile link. |
srOnlyText? | string | — | Text for screen readers (e.g. "Your profile"). |
Related types
SmartSidebarNavLayout:'light' \| 'dark' \| 'with-expandable-sections' \| 'with-secondary-navigation' \| 'brand'
Replacing the Implementation
SmartSidebarNavigation renders the component registered under the 'sidebar-navigation' key of SmartProvider's components, and SmartSidebarNavigationStandard when nothing is registered there. Every SmartSidebarNavigation below the provider then renders the registered component, which receives the same props.
There is no preset for this component: register a component of your own that takes SmartSidebarNavigationProps, as shown below, as components={{ 'sidebar-navigation': MySidebarNavigation }}. Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useSidebarNavigation hook
The behaviour every sidebar navigation variant shares: options.items normalised into a first, untitled group followed by options.groups; the expanded state of the expandable items, starting from item.expanded and flipped by toggleExpanded (reported through onItemToggle); and the item click.
| Returns | Type | Description |
|---|---|---|
groups | ISidebarNavGroup[] | options.items as a first untitled group, then options.groups. |
isExpanded | (item: ISidebarNavItem) => boolean | Whether an expandable item is open. |
toggleExpanded | (item: ISidebarNavItem) => void | Opens or closes an item and reports onItemToggle. |
itemClick | (itemId: string) => void | undefined | Reports a click on an item without href. |
import { useState } from 'react';
import {
cn,
ISidebarNavOptions,
SmartProvider,
SmartSidebarNavigation,
SmartSidebarNavigationProps,
useSidebarNavigation,
} from '@smartsoft001/react';
export function CustomSidebarNavigation(props: SmartSidebarNavigationProps) {
const { options, className } = props;
// useSidebarNavigation merges the flat items and the named groups into one
// list, keeps the expanded sections and reports clicks and toggles.
const { groups, isExpanded, toggleExpanded, itemClick } =
useSidebarNavigation(props);
return (
<nav
className={cn(
'docs-sidebar-navigation',
`docs-sidebar-navigation--${options?.layout ?? 'light'}`,
className,
)}
aria-label={options?.ariaLabel ?? 'Sidebar'}
>
{groups.map((group, index) => (
<div key={group.id ?? index} className="docs-sidebar-navigation__group">
{group.title && (
<p className="docs-sidebar-navigation__group-title">
{group.title}
</p>
)}
<ul>
{group.items.map((item) => (
<li key={item.id}>
{item.expandable ? (
<>
<button
type="button"
className="docs-sidebar-navigation__toggle"
aria-expanded={isExpanded(item)}
onClick={() => toggleExpanded(item)}
>
{item.label}
</button>
{isExpanded(item) && (
<ul className="docs-sidebar-navigation__children">
{(item.children ?? []).map((child) => (
<li key={child.id}>
<a
className="docs-sidebar-navigation__child-link"
href={child.href}
onClick={() => itemClick(child.id)}
>
{child.label}
</a>
</li>
))}
</ul>
)}
</>
) : (
<a
className="docs-sidebar-navigation__link"
href={item.href}
aria-current={item.current ? 'page' : undefined}
onClick={() => itemClick(item.id)}
>
{item.initial && (
<span className="docs-sidebar-navigation__initial">
{item.initial}
</span>
)}
<span>{item.label}</span>
{item.badge !== undefined && (
<span className="docs-sidebar-navigation__badge">
{item.badge}
</span>
)}
</a>
)}
</li>
))}
</ul>
</div>
))}
{options?.profile && (
<a
className="docs-sidebar-navigation__profile"
href={options.profile.href}
>
{options.profile.name}
</a>
)}
</nav>
);
}
// A module constant: a new object on every render would change the context.
const components = { 'sidebar-navigation': CustomSidebarNavigation };
const options: ISidebarNavOptions = {
layout: 'light',
ariaLabel: 'Sidebar',
items: [
{ id: 'dashboard', label: 'Dashboard', href: '#', current: true },
{ id: 'team', label: 'Team', href: '#', badge: 5 },
{ id: 'projects', label: 'Projects', href: '#', badge: 12 },
{
id: 'teams',
label: 'Teams',
expandable: true,
children: [
{ id: 'engineering', label: 'Engineering', href: '#' },
{ id: 'human-resources', label: 'Human Resources', href: '#' },
],
},
],
groups: [
{
id: 'your-teams',
title: 'Your teams',
items: [
{
id: 'engineering-team',
label: 'Engineering',
initial: 'E',
href: '#',
},
{ id: 'marketing-team', label: 'Marketing', initial: 'M', href: '#' },
],
},
],
profile: { name: 'Tom Cook', href: '#', srOnlyText: 'Your profile' },
};
export function SidebarNavigationCustomExample() {
const [activeItem, setActiveItem] = useState<string | null>(null);
// Every SmartSidebarNavigation below the provider renders
// CustomSidebarNavigation, which receives the same props, onItemClick included.
return (
<SmartProvider components={components}>
<SmartSidebarNavigation
options={options}
onItemClick={({ itemId }) => setActiveItem(itemId)}
/>
{activeItem && <p>Active item: {activeItem}</p>}
</SmartProvider>
);
}
Styling
- The standard rendering is unstyled semantic markup with class hooks (
sidebar-logo,sidebar-logo-img-dark,item-badge,item-initial, ...): style them, or register your own component.
Source
The component lives in packages/shared/react/src/lib/components/sidebar-navigation and is documented for Claude Code by the react-components-sidebar-navigation skill.