Vertical Navigation
The <smart-vertical-navigation> component renders a sidebar navigation with one or more groups of items. Each item can have an icon (template), an optional badge, an optional initial (used for project-style sidebars), and an href (rendered as <a>) or no href (rendered as <button> emitting itemClick). It follows the Base + Standard + Wrapper pattern with an InjectionToken-based extension mechanism. The abstract VerticalNavigationBaseComponent defines the shared API — options (IVerticalNavOptions), cssClass (alias class), and the itemClick output. VerticalNavigationStandardComponent is a barebones placeholder using native <nav>, <ul>, <li>, <a> and <button> elements. VerticalNavigationComponent is the public wrapper that renders VerticalNavigationStandardComponent by default and accepts a custom replacement via VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN.
Usage
<smart-vertical-navigation
[options]="options"
(itemClick)="onItemClick($event)"
/>
@if (lastItem()) {
<p>Last clicked item: {{ lastItem() }}</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
VerticalNavigationComponent (<smart-vertical-navigation>)
Main wrapper. Delegates to VerticalNavigationStandardComponent by default. When VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN is provided, renders the injected component via NgComponentOutlet and hands it options and class. Re-emits itemClick of whichever implementation renders (the standard, the preset or a custom one).
VerticalNavigationStandardComponent (<smart-vertical-navigation-standard>)
Barebones placeholder using native HTML. Renders an outer wrapper with cssClass, a <nav class="vertical-navigation"> (with aria-label from options.ariaLabel or default "Sidebar"), and a <ul class="groups"> with one <li class="group"> per group. Each group renders an optional <div class="group-title"> and a <ul class="items">, which the title names (aria-labelledby); each item renders as <a class="item-link"> (when href is provided; a click follows the link) or <button class="item-button"> (otherwise, emitting itemClick). Items get the current class and aria-current="page" when item.current === true. Inside an item: iconTpl (or, without it, initial), label and badge. The standard does not read options.layout and adds no styles: the class hooks are for your CSS.
VerticalNavigationPresetComponent (<smart-vertical-navigation-preset>)
Fully-styled, drop-in concrete implementation extending VerticalNavigationBaseComponent. Register it through VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN (or every preset at once with provideSmartPresets()) to restyle every <smart-vertical-navigation>, or use the <smart-vertical-navigation-preset> selector directly. Renders the Preline vertical-tabs look: one <nav> landmark (named by options.ariaLabel, default "Sidebar") with a trailing border (border-e-2) holds every group; a group is its title, when set, followed by a <ul role="list"> of the items that the title names (aria-labelledby), so a screen reader announces one navigation and a list per group ("Workspace", "Account"). Each item is a tab (<a> for href, <button> emitting itemClick otherwise) with its own trailing border, inside an <li>. The current item gains the primary accent (border-blue-600, text-blue-600, font-medium) and aria-current="page"; inactive items are muted gray with a primary hover/focus. Supports iconTpl, initial, label and badge. It does not read options.layout either. All classes are smart:-prefixed Tailwind with explicit dark: variants; the class recipes are internal to the preset and not exported.
VerticalNavigationPresetComponentdeclarescssClassasinput<string>('')without theclassalias. Bind it as[cssClass]when using the<smart-vertical-navigation-preset>selector directly, or just passclasson<smart-vertical-navigation>(the wrapper forwards it). With the preset registered through the token,(itemClick)on<smart-vertical-navigation>works as with the standard.
VerticalNavigationBaseComponent (abstract)
Abstract base directive. Exposes:
options: InputSignal<IVerticalNavOptions | undefined>cssClass: InputSignal<string>(aliasclass)itemClick: OutputEmitterRef<IVerticalNavItemClick>- protected
resolvedGroups: Signal<IVerticalNavGroup[]>:options.itemsas a first, untitled group, followed byoptions.groups
API
Inputs
| Input | Type | Default | Description |
|---|---|---|---|
options | InputSignal<IVerticalNavOptions | undefined> | - | Vertical navigation configuration |
class | InputSignal<string> | '' | External CSS classes (alias for cssClass) |
Outputs
| Output | Type | Description |
|---|---|---|
itemClick | OutputEmitterRef<IVerticalNavItemClick> | Emitted when an item without href (a button) is clicked. |
IVerticalNavOptions
| Field | Type | Default | Description |
|---|---|---|---|
items | IVerticalNavItem[] | [] | Items of a first, untitled group. |
groups | IVerticalNavGroup[] | [] | Further groups, rendered after items. |
ariaLabel | string | 'Sidebar' | Accessible name of the navigation's one <nav> landmark (the groups are lists named by their title). |
layout | SmartVerticalNavLayout | - | Not read by the built-in implementations (standard and preset); available to a custom implementation. |
SmartVerticalNavLayout is 'simple' | 'with-badges' | 'with-icons' | 'with-icons-and-badges' | 'with-secondary-navigation' | 'on-gray'.
IVerticalNavGroup
| Field | Type | Default | Description |
|---|---|---|---|
id | string | - | Track key of the group (the index without it). |
title | string | - | Heading above the group's items. |
items | IVerticalNavItem[] | required | The group's items. |
IVerticalNavItem
| Field | Type | Default | Description |
|---|---|---|---|
id | string | required | Reported as itemId in itemClick. |
label | string | - | Item text. |
href | string | - | Renders the item as a link; without it the item is a button emitting itemClick. |
current | boolean | false | Marks the item as the current page (aria-current="page"). |
badge | string | number | - | A count or text badge after the label. |
iconTpl | TemplateRef<unknown> | - | Icon before the label. |
initial | string | - | A letter shown before the label when there is no iconTpl (project lists). |
IVerticalNavItemClick
| Field | Type | Default | Description |
|---|---|---|---|
itemId | string | required | The id of the clicked item. |
VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN
Provide a component class extending VerticalNavigationBaseComponent under VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN; every <smart-vertical-navigation> below that injector renders it.
Extending the base class
import {
ChangeDetectionStrategy,
Component,
computed,
signal,
ViewEncapsulation,
} from '@angular/core';
import {
IVerticalNavOptions,
VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN,
VerticalNavigationBaseComponent,
VerticalNavigationComponent,
} from '@smartsoft001/angular';
@Component({
selector: 'docs-custom-vertical-navigation',
template: `
<nav
[class]="containerClasses()"
[attr.aria-label]="options()?.ariaLabel ?? 'Sidebar'"
>
<!--
The base normalizes options.items and options.groups into one list of
groups, so the implementation only has to render groups.
-->
@for (group of groups(); track group.id ?? $index) {
<div class="docs-vertical-nav__group">
@if (group.title) {
<div class="docs-vertical-nav__group-title">{{ group.title }}</div>
}
<ul role="list">
@for (item of group.items; track item.id) {
<li [class]="itemClasses(item.current)">
@if (item.href) {
<a
[href]="item.href"
[attr.aria-current]="item.current ? 'page' : null"
>
@if (item.initial) {
<span class="docs-vertical-nav__initial">
{{ item.initial }}
</span>
}
<span>{{ item.label ?? item.id }}</span>
@if (item.badge !== undefined && item.badge !== null) {
<span class="docs-vertical-nav__badge">
{{ item.badge }}
</span>
}
</a>
} @else {
<button type="button" (click)="onItemClick(item.id)">
{{ item.label ?? item.id }}
</button>
}
</li>
}
</ul>
</div>
}
</nav>
`,
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CustomVerticalNavigationComponent extends VerticalNavigationBaseComponent {
groups = computed(() => this.resolvedGroups());
containerClasses = computed(() =>
[
'docs-vertical-nav',
`docs-vertical-nav--${this.options()?.layout ?? 'simple'}`,
this.cssClass(),
]
.filter(Boolean)
.join(' '),
);
protected itemClasses(current: boolean | undefined): string {
return current
? 'docs-vertical-nav__item docs-vertical-nav__item--current'
: 'docs-vertical-nav__item';
}
protected onItemClick(itemId: string): void {
this.itemClick.emit({ itemId });
}
}
@Component({
selector: 'docs-vertical-navigation-custom-example',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [VerticalNavigationComponent],
// The token swaps the standard navigation for the custom one everywhere below
// this component, so consumers keep writing `<smart-vertical-navigation>`.
providers: [
{
provide: VERTICAL_NAVIGATION_STANDARD_COMPONENT_TOKEN,
useValue: CustomVerticalNavigationComponent,
},
],
// The wrapper re-emits `itemClick` of the custom component.
template: `
<smart-vertical-navigation
[options]="options"
(itemClick)="lastItem.set($event.itemId)"
/>
@if (lastItem()) {
<p>Last clicked item: {{ lastItem() }}</p>
}
`,
})
export class VerticalNavigationCustomExampleComponent {
readonly lastItem = signal<string | null>(null);
// `items` and `groups` can be combined: the base puts the loose items in a
// first, untitled group and appends the explicit groups after them.
options: IVerticalNavOptions = {
// The built-in implementations do not read `layout`; this custom one turns
// it into a class.
layout: 'with-badges',
ariaLabel: 'Sidebar',
items: [
{ id: 'dashboard', label: 'Dashboard', href: '#dashboard' },
{ id: 'team', label: 'Team', href: '#team', current: true, badge: 5 },
{ id: 'calendar', label: 'Calendar', href: '#calendar' },
],
groups: [
{
id: 'projects',
title: 'Projects',
items: [
{
id: 'website',
label: 'Website redesign',
href: '#website',
initial: 'W',
},
{ id: 'new-project', label: 'New project' },
],
},
],
};
}
Source
The component lives in packages/shared/angular/src/lib/components/vertical-navigation and is documented for Claude Code by the angular-components-vertical-navigation skill.
SmartVerticalNavigation renders a vertical list of navigation items: options.items (an untitled first group) followed by titled options.groups. Items show an icon or an initial, a label and a badge; the current one is highlighted. 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 }). SmartVerticalNavigationPreset renders vertical tabs with an accented current item.
Usage
import { useState } from 'react';
import {
IVerticalNavItemClick,
IVerticalNavOptions,
SmartVerticalNavigation,
} from '@smartsoft001/react';
const options: IVerticalNavOptions = {
ariaLabel: 'Main',
items: [
{ id: 'dashboard', label: 'Dashboard', current: true },
{ id: 'team', label: 'Team', badge: 5 },
{ id: 'projects', label: 'Projects', badge: 12 },
{ id: 'reports', label: 'Reports' },
],
};
export function VerticalNavigationUsageExample() {
const [lastItem, setLastItem] = useState<string | null>(null);
const onItemClick = ({ itemId }: IVerticalNavItemClick) =>
setLastItem(itemId);
return (
<>
<SmartVerticalNavigation options={options} onItemClick={onItemClick} />
{lastItem && <p>Last clicked item: {lastItem}</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 |
|---|---|---|
SmartVerticalNavigation | component | Renders the implementation registered as components['vertical-navigation'] on SmartProvider, SmartVerticalNavigationStandard by default. |
SmartVerticalNavigationPreset | component | Styled vertical navigation variation (preset). |
SmartVerticalNavigationStandard | component | The default vertical navigation rendering. |
useVerticalNavigation | hook | The behaviour every vertical navigation variant shares: options.items normalised into a first, untitled group followed by options.groups, and the item click. |
The preset's class helpers (getVerticalNavContainerClasses for the <nav>, getVerticalNavNavClasses for a group's list, getVerticalNavListItemClasses, getVerticalNavGroupTitleClasses, getVerticalNavItemClasses, getVerticalNavIconClasses, getVerticalNavInitialClasses, getVerticalNavBadgeClasses) are exported too, for a custom implementation that wants the preset look.
Props and Types
SmartVerticalNavigationProps
| Prop | Type | Default | Description |
|---|---|---|---|
options? | IVerticalNavOptions | — | Items and groups. |
className? | string | — | Classes on the root element. |
onItemClick? | (event: IVerticalNavItemClick) => void | — | A click on an item without href. |
IVerticalNavOptions
| Field | Type | Default | Description |
|---|---|---|---|
layout? | SmartVerticalNavLayout | — | Not read by the built-in implementations (standard and preset); available to a custom implementation. |
ariaLabel? | string | 'Sidebar' | Accessible name of the one nav landmark (the groups are lists named by their title). |
items? | IVerticalNavItem[] | — | The first, untitled group. |
groups? | IVerticalNavGroup[] | — | Further groups, each with a title. |
IVerticalNavItemClick
| Field | Type | Default | Description |
|---|---|---|---|
itemId | string | required | The id of the clicked item. |
IVerticalNavItem
| 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 item. |
badge? | string | number | — | A count or text badge. |
iconTpl? | ReactNode | — | Item icon. |
initial? | string | — | A letter shown instead of an icon. |
IVerticalNavGroup
| Field | Type | Default | Description |
|---|---|---|---|
id? | string | — | Key of the group. |
title? | string | — | Group heading. |
items | IVerticalNavItem[] | required | The group's items. |
Related types
SmartVerticalNavLayout:'simple' \| 'with-badges' \| 'with-icons' \| 'with-icons-and-badges' \| 'with-secondary-navigation' \| 'on-gray'
Replacing the Implementation
SmartVerticalNavigation renders the component registered under the 'vertical-navigation' key of SmartProvider's components, and SmartVerticalNavigationStandard when nothing is registered there. Every SmartVerticalNavigation below the provider then renders the registered component, which receives the same props.
SmartVerticalNavigationPreset is the styled (preset) implementation: register it under the 'vertical-navigation' key of SmartProvider's components, render it directly in place of SmartVerticalNavigation, or spread SMART_PRESET_COMPONENTS on the provider to register every preset at once (see the react-provider skill). Pass components as a stable object (a module constant or a memoised value), or the context changes on every render.
The useVerticalNavigation hook
The behaviour every vertical navigation variant shares: options.items normalised into a first, untitled group followed by options.groups, and the item click.
| Returns | Type | Description |
|---|---|---|
groups | IVerticalNavGroup[] | options.items as a first untitled group, then options.groups. |
itemClick | (itemId: string) => void | undefined | Reports a click on an item without href. |
import { useState } from 'react';
import {
IVerticalNavOptions,
SmartProvider,
SmartVerticalNavigation,
SmartVerticalNavigationProps,
useVerticalNavigation,
} from '@smartsoft001/react';
export function CustomVerticalNavigation(props: SmartVerticalNavigationProps) {
const { options, className } = props;
// useVerticalNavigation normalises options.items and options.groups into one
// list of groups and reports clicks through onItemClick.
const { groups, itemClick } = useVerticalNavigation(props);
const containerClasses = [
'docs-vertical-nav',
`docs-vertical-nav--${options?.layout ?? 'simple'}`,
className,
]
.filter(Boolean)
.join(' ');
return (
<nav
className={containerClasses}
aria-label={options?.ariaLabel ?? 'Sidebar'}
>
{groups.map((group, index) => (
<div key={group.id ?? index} className="docs-vertical-nav__group">
{group.title && (
<div className="docs-vertical-nav__group-title">{group.title}</div>
)}
<ul role="list">
{group.items.map((item) => (
<li
key={item.id}
className={
item.current
? 'docs-vertical-nav__item docs-vertical-nav__item--current'
: 'docs-vertical-nav__item'
}
>
{item.href ? (
<a
href={item.href}
aria-current={item.current ? 'page' : undefined}
>
{item.initial && (
<span className="docs-vertical-nav__initial">
{item.initial}
</span>
)}
<span>{item.label ?? item.id}</span>
{item.badge !== undefined && item.badge !== null && (
<span className="docs-vertical-nav__badge">
{item.badge}
</span>
)}
</a>
) : (
<button type="button" onClick={() => itemClick(item.id)}>
{item.label ?? item.id}
</button>
)}
</li>
))}
</ul>
</div>
))}
</nav>
);
}
// A module constant: a new object on every render would change the context.
const components = { 'vertical-navigation': CustomVerticalNavigation };
// `items` and `groups` can be combined: the hook puts the loose items in a
// first, untitled group and appends the explicit groups after them.
const options: IVerticalNavOptions = {
// The built-in implementations do not read `layout`; this custom one turns it
// into a class.
layout: 'with-badges',
ariaLabel: 'Sidebar',
items: [
{ id: 'dashboard', label: 'Dashboard', href: '#dashboard' },
{ id: 'team', label: 'Team', href: '#team', current: true, badge: 5 },
{ id: 'calendar', label: 'Calendar', href: '#calendar' },
],
groups: [
{
id: 'projects',
title: 'Projects',
items: [
{
id: 'website',
label: 'Website redesign',
href: '#website',
initial: 'W',
},
{ id: 'new-project', label: 'New project' },
],
},
],
};
// Every <SmartVerticalNavigation> below the provider renders
// CustomVerticalNavigation.
export function VerticalNavigationCustomExample() {
const [lastItem, setLastItem] = useState<string | null>(null);
return (
<SmartProvider components={components}>
<SmartVerticalNavigation
options={options}
onItemClick={({ itemId }) => setLastItem(itemId)}
/>
{lastItem && <p>Last clicked item: {lastItem}</p>}
</SmartProvider>
);
}
Styling
- Both renderings put every group in one
<nav>landmark (named byoptions.ariaLabel,'Sidebar'by default); a group is a list (role="list") of its items, named by its title througharia-labelledby. The standard rendering is unstyled; the preset renders the vertical tabs, each group's title before its list, withsmart:dark:variants.
Source
The component lives in packages/shared/react/src/lib/components/vertical-navigation and is documented for Claude Code by the react-components-vertical-navigation skill.