Primitives
Navigation Menu
A site-navigation header built on the disclosure pattern: buttons that expand panels of links into a shared viewport.
Open a section from the bar and move between them. The active trigger carries data-state="open", and data-motion says which way the viewport slid to reach it.
A <nav> of disclosures, not an ARIA menu. Triggers are buttons with aria-expanded / aria-controls, content panels are the plain regions of links those triggers disclose, Tab moves through links, Escape closes and returns focus.
Anatomy
<nav forNavigationMenu [(value)]="open" ariaLabel="Main">
<ul forNavigationMenuList>
<li forNavigationMenuItem value="products">
<button forNavigationMenuTrigger>Products</button>
<!-- @if (open() === 'products') { -->
<div forNavigationMenuContent>
<a href="/p/web" forNavigationMenuLink>Web</a>
<a href="/p/mobile" forNavigationMenuLink active>Mobile</a>
</div>
<!-- } -->
</li>
<span forNavigationMenuIndicator></span>
</ul>
<!-- Optional shared surface for mega-menu animations -->
<div forNavigationMenuViewport></div>
</nav>
Examples
Vertical orientation
orientation='vertical' stacks the triggers into a sidebar and swaps the keyboard axis: ArrowUp / ArrowDown move focus across triggers, and the inline-end arrow opens the focused panel: ArrowRight, or ArrowLeft under dir="rtl". Each panel flies out beside its trigger and the indicator becomes a vertical bar tracking the active row.
Limitations
- Nested submenus are not implemented; they are tracked separately.
Scoped defaults
provideForNavigationMenuDefaults configures navigation menu defaults for an injector subtree, either at the application root or in any component's providers array. Partial overrides inherit unspecified keys from the parent scope (or the library fallbacks at the root).
| Key | Library fallback | Meaning | |
|---|---|---|---|
openDelay | 200 | Milliseconds before a hover opens an item, for menus that don't set openDelay themselves. | |
closeDelay | 150 | Milliseconds before an item closes after the pointer leaves, for menus that don't set closeDelay themselves. | |
skipDelayDuration | 300 | Milliseconds after a peer item closed during which the next open is instant, for menus that don't set skipDelayDuration themselves. | |
loop | true | Whether arrow navigation wraps past the first / last enabled trigger, for menus that don't set loop themselves. |
Per-instance inputs always win over the scope defaults.
import { type ApplicationConfig } from '@angular/core';
import { provideForNavigationMenuDefaults } from 'forty-cdk/defaults';
export const appConfig: ApplicationConfig = {
providers: [provideForNavigationMenuDefaults({ openDelay: 100, closeDelay: 300 })],
};
API
ForNavigationMenu
| Property | Type | Description |
|---|---|---|
value | model | Two-way bindable. Open item id, or null when nothing is open.Default: null |
orientation | input | Default: 'horizontal' |
dir | input | RTL inverts ArrowLeft / ArrowRight: across the triggers when horizontal, and as the open key when vertical. null inherits the nearest [dir] / <html dir>, else 'ltr'.Default: null |
loop | input | Whether arrow nav wraps. Default: true |
disabled | input | Disables the whole menu. Default: false |
ariaLabel | input | Reactive aria-label for the <nav>.Default: null (and empty string) emits no attribute; prefer native aria-labelledby when a visible label exists |
openDelay | input | ms before a hover opens a panel. Focus never opens one. Default: 200 |
closeDelay | input | ms before pointer-leave closes. Default: 150 |
skipDelayDuration | input | ms after a peer closes during which the next open is instant. Default: 300 |
ForNavigationMenuItem
| Property | Type | Description |
|---|---|---|
value | input | Identifier matched against the menu's value, shared by the item's trigger and content. Required in practice though not by the template compiler: an item left unbound throws in dev mode.Default: โ |
disabled | input | Disables this item's trigger. The root's disabled disables it too.Default: false |
ForNavigationMenuLink
| Property | Type | Description |
|---|---|---|
active | input | Marks the link as pointing at the current page: reflects data-active and aria-current.Default: false |
ariaCurrent | input | Value written to aria-current while active is true.Default: 'page' |
Data attributes
| Piece | Attribute | Values | |
|---|---|---|---|
[forNavigationMenu] | data-state | open | closed | |
[forNavigationMenu] | data-orientation | horizontal | vertical | |
[forNavigationMenu] | data-disabled | present | absent | |
[forNavigationMenuList] | data-orientation | horizontal | vertical | |
[forNavigationMenuItem] | data-state | open | closed | |
[forNavigationMenuItem] | data-disabled | present | absent | |
[forNavigationMenuTrigger] | data-state | open | closed | |
[forNavigationMenuTrigger] | data-disabled | present | absent | |
[forNavigationMenuContent] | data-state | open | closed | |
[forNavigationMenuContent] | data-motion | from-start | from-end | to-start | to-end | |
[forNavigationMenuLink] | data-active | present | absent | |
[forNavigationMenuIndicator] | data-state | visible | hidden | |
[forNavigationMenuIndicator] | data-orientation | horizontal | vertical | |
[forNavigationMenuViewport] | data-state | open | closed | |
[forNavigationMenuViewport] | data-orientation | horizontal | vertical |
data-motion is absent when a panel opens from a closed menu and when a panel closes, where there is no peer trigger to compare against.
Keyboard
| Key | Behavior | |
|---|---|---|
| Tab | Moves into the trigger row. From an open trigger, moves into its panel and through its links, then on to the next trigger, wherever a Viewport renders the panel. | |
| Shift+Tab | The same path in reverse: from the next trigger into the open panel's last link, and from its first link back to the trigger. | |
| Enter / Space | Toggles the focused trigger. | |
| ArrowDown (horizontal) / ArrowRight (vertical, LTR) / ArrowLeft (vertical, RTL) | Opens the focused trigger. | |
| ArrowLeft / ArrowRight (horizontal) | Moves focus across triggers. | |
| ArrowUp / ArrowDown (vertical) | Moves focus across triggers. | |
| Home / End | Jump to first / last enabled trigger. | |
| Escape | Closes and returns focus to the trigger. |
Accessibility
Implements the WAI-ARIA Disclosure Navigation Menu pattern.
- Not an ARIA menu. This implements the disclosure pattern:
<nav>+ buttons + the panels they disclose. ARIArole="menu"is for application menus where Tab leaves but arrows do everything. Site navigation expects Tab to move through links, which is what this primitive supports. - Focus alone does not open. A trigger opens on mouse hover, click, Enter / Space, or the cross-axis arrow (ArrowDown horizontal, ArrowRight vertical, ArrowLeft vertical under RTL), but never on plain focus. This matches the APG disclosure-navigation pattern: Tabbing across the trigger row does not auto-expand panels, and the return-focus after Escape cannot synchronously re-open the panel that just closed.
- Escape belongs to whatever holds focus. Escape closes the open panel only while focus is inside the navigation: a trigger, the Viewport or the active panel. Pressed anywhere else, for instance in a popover that kept focus while a panel hover-opened above it, the key goes to that overlay instead, so the popover closes and the panel stays. An Escape that cancels an IME composition in a field inside a panel closes nothing.
- Hover is a mouse affordance. The
pointerenter/pointerleaveopen-and-close path on both the trigger and the panel is gated topointerType === 'mouse'. Touch and pen fire those events around every tap, so honouring them would open a panel mid-press and let the follow-up tap toggle it straight back shut; on those devices a tap drives the panel through the nativeclickinstead. - Trigger labels are mandatory. Each
[forNavigationMenuTrigger]needs visible text or anaria-label. The directive does not invent one. - Disabled triggers stay focusable. A trigger is disabled by its own item's
[disabled]or by the root's (the two are OR'd), and the state is reflected on the trigger asaria-disabled="true"+data-disabled, never as the nativedisabledattribute. The trigger therefore keeps its place in the tab order and screen readers still announce it as unavailable, while clicks, hover-opens and keyboard activation are no-ops and arrow navigation skips it. A focused disabled trigger still answers the arrow keys and Home / End, so a keyboard user can move along the row from it. Key disabled styling off[data-disabled], not:disabled. The[forNavigationMenuItem]host's owndata-disabledreflects its per-item[disabled]only; the merged state lives on the trigger. - Panels carry no role and no accessible name. As in the APG example, a panel is the region its trigger's
aria-expanded/aria-controlsdiscloses, not a landmark, and[forNavigationMenuContent]emits neither arolenoraria-labelledby. A<div>maps to thegenericrole, on which ARIA prohibits a name. To give a panel a landmark, put the directive on an element that has one and name it yourself, for instance<section forNavigationMenuContent aria-labelledby="products-heading">; the directive leaves both attributes alone. - Content panels are mounted via
@if. The directive does not apply[hidden]; visibility is the consumer's call. Useanimate.enter/animate.leavefor transitions. aria-controlsis emitted only while the panel is there to point at. The trigger drops the attribute entirely, rather than emitting it empty, whenever the open item's[forNavigationMenuContent]is not mounted, so the reference never dangles. The pairing is resolved synchronously in the first render pass, which is what makes it present in server-rendered markup too: a screen reader reading the pre-hydration document gets the samearia-controlslinkage a hydrated one does.- Indicator follows the active trigger. A
ResizeObserver(browser-only) watches the active trigger and the surrounding list and re-measures only when the active trigger switches or one of those boxes resizes. Measurement is reactive, not per-render polling. Consumers drive the visual via the--for-navigation-menu-indicator-x|y|width|heightcustom properties. The offsets are in the list's scrolled content coordinates, so the indicator stays under its trigger while an overflowing trigger row scrolls. When the menu closes, the properties keep the last geometry and onlydata-stateturnshidden, so a transition on them fades the indicator out in place instead of sweeping it back to the start of the list. data-stateon the root. The[forNavigationMenu]host reflectsdata-state="open"whenever any item is open and"closed"otherwise. The attribute uses the same vocabulary as the trigger / content / item / indicator pieces and is useful for top-level CSS hooks (e.g. dimming the rest of the page while the menu is open).- Tab-out closes. Per APG, moving focus out of the navigation closes any open panel. There is one containment rule behind it: focus counts as inside while it is on the nav host, the Viewport or the active panel, or while it is inside any overlay stacked on top of them, so a popover or hovercard opened from a panel never dismisses the panel it is anchored to. Moving between those never dismisses. It holds wherever the Viewport is stamped: a panel re-parented outside the
<nav>is still part of the surface. It also holds for a leave that reports no destination at all (focusoutwith anullrelatedTarget: focus leaving the document, or landing on a non-focusable area), which is resolved againstdocument.activeElementonce the focus move has settled. Pressing a non-focusable region inside the panel drops focus to<body>without leaving the widget, so it does not dismiss. When a dismissible overlay of your own is open on top of the navigation (a dialog opened from a mega-menu link), that overlay owns the focus leave and the navigation stays open behind it until its own turn comes.
Styling
forty-cdk ships no styles: put your own class on each piece and key your CSS off the data-* attributes listed under Data attributes, not off the for* selectors (Styling forty-cdk explains why).
CSS custom properties
[forNavigationMenuIndicator] exposes the active trigger's geometry (relative to the padding box of [forNavigationMenuList], scroll included) so the indicator visual can be driven entirely from CSS. The optional shared [forNavigationMenuViewport] exposes the active panel's natural size so consumers can transition width / height between trigger groups.
| Property | Meaning | |
|---|---|---|
--for-navigation-menu-indicator-x | Horizontal offset of the active trigger (px). | |
--for-navigation-menu-indicator-y | Vertical offset of the active trigger (px). | |
--for-navigation-menu-indicator-width | Active trigger width (px). | |
--for-navigation-menu-indicator-height | Active trigger height (px). | |
--for-navigation-menu-viewport-width | Active content's natural width (px), on the Viewport. | |
--for-navigation-menu-viewport-height | Active content's natural height (px), on the Viewport. |
.navigation-menu-trigger svg {
transition: transform 150ms;
}
.navigation-menu-trigger[data-state='open'] svg {
transform: rotate(180deg);
}
.navmenu-indicator {
transform: translateX(var(--for-navigation-menu-indicator-x));
width: var(--for-navigation-menu-indicator-width);
transition:
transform 200ms,
width 200ms;
}
.navmenu-indicator[data-state='hidden'] {
opacity: 0;
}
Wrapping in a design system
Subclass the root and re-provide FOR_NAVIGATION_MENU_CONTEXT with useExisting pointing at the subclass, since Angular does not inherit a directive's providers; Wrapping non-form roots walks the pattern.