Navigation Menu
Site navigation with panels of links: opened by hover, click or keyboard, in one box that moves from item to item.
Usage
import { Component, ViewEncapsulation } from '@angular/core';import { RouterLink, RouterLinkActive } from '@angular/router';import { ScNavigationMenu, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList, ScNavigationMenuTrigger, ScNavigationMenuTriggerIcon,} from '@semantic-components/ui';import { SiChevronDownIcon, SiCircleAlertIcon, SiCircleCheckIcon, SiCircleDashedIcon,} from '@semantic-icons/lucide-icons';
/** shadcn's demo: panels of links under their triggers, sharing one box; a link on its own (Docs), active on its pages. */@Component({ selector: 'app-navigation-menu-usage-demo', imports: [ RouterLink, RouterLinkActive, ScNavigationMenu, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList, ScNavigationMenuTrigger, ScNavigationMenuTriggerIcon, SiChevronDownIcon, SiCircleAlertIcon, SiCircleCheckIcon, SiCircleDashedIcon, ], template: ` <nav scNavigationMenu aria-label="Main"> <ul scNavigationMenuList> <li scNavigationMenuItem value="getting-started"> <button scNavigationMenuTrigger> Getting started <svg siChevronDownIcon scNavigationMenuTriggerIcon></svg> </button> <div scNavigationMenuContent> <ul class="w-96"> @for (page of gettingStarted; track page.link) { <li> <a scNavigationMenuLink [routerLink]="page.link"> <div class="flex flex-col gap-1 text-sm"> <div class="leading-none font-medium"> {{ page.title }} </div> <div class="text-muted-foreground line-clamp-2"> {{ page.text }} </div> </div> </a> </li> } </ul> </div> </li> <li scNavigationMenuItem value="components" class="hidden md:flex"> <button scNavigationMenuTrigger> Components <svg siChevronDownIcon scNavigationMenuTriggerIcon></svg> </button> <div scNavigationMenuContent> <ul class="grid w-[400px] grid-cols-1 gap-2 md:w-[500px] md:grid-cols-2 lg:w-[600px]" > @for (component of components; track component.link) { <li> <a scNavigationMenuLink [routerLink]="component.link"> <div class="flex flex-col gap-1 text-sm"> <div class="leading-none font-medium"> {{ component.title }} </div> <div class="text-muted-foreground line-clamp-2"> {{ component.text }} </div> </div> </a> </li> } </ul> </div> </li> <li scNavigationMenuItem value="with-icon"> <button scNavigationMenuTrigger> With Icon <svg siChevronDownIcon scNavigationMenuTriggerIcon></svg> </button> <div scNavigationMenuContent> <ul class="grid w-[200px]"> <li> <a scNavigationMenuLink routerLink="." fragment="backlog"> <svg siCircleAlertIcon></svg> Backlog </a> <a scNavigationMenuLink routerLink="." fragment="to-do"> <svg siCircleDashedIcon></svg> To Do </a> <a scNavigationMenuLink routerLink="." fragment="done"> <svg siCircleCheckIcon></svg> Done </a> </li> </ul> </div> </li> <li scNavigationMenuItem> <a scNavigationMenuLink routerLink="/docs/overview/get-started" routerLinkActive #docs="routerLinkActive" [active]="docs.isActive" > Docs </a> </li> </ul> </nav> `, host: { class: 'flex w-full justify-center' }, encapsulation: ViewEncapsulation.None,})export class NavigationMenuUsageDemo { private readonly gettingStarted = [ { link: '/docs/overview/introduction', title: 'Introduction', text: 'Accessible Angular components, styled with Tailwind.', }, { link: '/docs/overview/get-started', title: 'Installation', text: 'How to install dependencies and structure your app.', }, { link: '/docs/components/typeset', title: 'Typeset', text: 'Styles for headings, paragraphs, lists…', }, ];
private readonly components = [ { link: '/docs/components/alert-dialog', title: 'Alert Dialog', text: 'A modal dialog that interrupts with important content and expects a response.', }, { link: '/docs/components/preview-card', title: 'Preview Card', text: 'A preview of the content behind a link.', }, { link: '/docs/components/progress', title: 'Progress', text: 'How far a task has gone, as a bar.', }, { link: '/docs/components/scroll-area', title: 'Scroll Area', text: 'Scrolling, styled the same in every browser.', }, { link: '/docs/components/tabs', title: 'Tabs', text: 'Layered sections of content, shown one at a time.', }, { link: '/docs/components/tooltip', title: 'Tooltip', text: 'A short hint on hover or keyboard focus.', }, ];}Anatomy
A named nav and its list of items. An item holds a link, or a trigger and its panel — written inside the item, so Tab reaches its links right after the trigger.
import { ScNavigationMenu, ScNavigationMenuList, ScNavigationMenuItem, ScNavigationMenuTrigger, ScNavigationMenuTriggerIcon, ScNavigationMenuContent, ScNavigationMenuLink,} from '@semantic-components/ui';<nav scNavigationMenu aria-label="…"> <ul scNavigationMenuList> <li scNavigationMenuItem> <button scNavigationMenuTrigger> … <svg siChevronDownIcon scNavigationMenuTriggerIcon></svg> </button> <div scNavigationMenuContent> <a scNavigationMenuLink routerLink="…">…</a> </div> </li> <li scNavigationMenuItem> <a scNavigationMenuLink routerLink="…">…</a> </li> </ul></nav>Accessibility
- A disclosure navigation (WAI-ARIA), not a menu: a nav you name (aria-label), triggers with aria-expanded and aria-controls, plain links.
- Tab follows the page: a trigger, then its panel's links. ← and → move between the top-level items (mirrored right to left), Home and End too; ↓ goes into the open panel, ↑ and ↓ within it.
- Escape closes the panel and returns to its trigger; the focus leaving it, or a click outside, closes it too.
- A closed panel is invisible: out of the tab order and of the accessibility tree, still in the page for search engines.
- The link for the page shown is active (aria-current="page"); the chevron is hidden from screen readers.
Examples
Open Item
Open: none
import { Component, ViewEncapsulation, signal } from '@angular/core';import { RouterLink, RouterLinkActive } from '@angular/router';import { ScButton, ScNavigationMenu, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList, ScNavigationMenuTrigger,Separate Panels
import { Component, ViewEncapsulation } from '@angular/core';import { RouterLink, RouterLinkActive } from '@angular/router';import { ScNavigationMenu, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList, ScNavigationMenuTrigger, ScNavigationMenuTriggerIcon,Align
import { Component, ViewEncapsulation, signal } from '@angular/core';import { RouterLink, RouterLinkActive } from '@angular/router';import { ScButton, ScNavigationMenu, type ScNavigationMenuAlign, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList,RTL
import { Dir } from '@angular/cdk/bidi';import { Component, LOCALE_ID, ViewEncapsulation } from '@angular/core';import { RouterLink, RouterLinkActive } from '@angular/router';import { ScNavigationMenu, ScNavigationMenuContent, ScNavigationMenuItem, ScNavigationMenuLink, ScNavigationMenuList, ScNavigationMenuTrigger,API reference
Each part takes class, merged over the style (cn: a later class wins).
| Part | Selector | Description |
|---|---|---|
ScNavigationMenu | nav[scNavigationMenu] | The navigation. [(value)] (the open item's value, or null); delay and closeDelay (ms, 50); viewport (one shared box that moves between items, default; false: each panel its own); align ('start', 'center', 'end'): where panels line up under their trigger. |
ScNavigationMenuList | ul[scNavigationMenuList] | The top-level items, in a row. |
ScNavigationMenuItem | li[scNavigationMenuItem] | A top-level item: a link, or a trigger and its panel. value: its name in the menu’s value (one is made up if left out). |
ScNavigationMenuTrigger | button[scNavigationMenuTrigger] | Opens its item's panel on hover or press: the style's trigger, aria-expanded and aria-controls. |
ScNavigationMenuTriggerIcon | svg[scNavigationMenuTriggerIcon] | Your chevron after the trigger’s text: turned over while open, hidden from screen readers. |
ScNavigationMenuContent | div[scNavigationMenuContent] | The panel, after its trigger: the style's padding; always in the page, invisible while closed; slides in from the side you came from. Lay out its inside as you like. |
ScNavigationMenuLink | a[scNavigationMenuLink] | A link: the trigger's look at the top level, the style's link in a panel. active (aria-current="page"); closeOnClick (true): following it closes the menu. |