Controlled directory with inline subnavigation
A controlled Library flyout contains a second menu whose grouped destinations stay in the same panel.
Keyboard
- Open Library, then use the Foundations or Workflows triggers inside it.
- Tab or arrow keys enter the nested destination links.
- Escape closes the active level; selecting a real link closes the directory.
States covered
- Controlled top-level value
- Nested inline viewport
- Uncontrolled initial subgroup
- Disabled subgroup
- State visible outside the panel
Install this complete example and its component dependencies.
npx shadcn@latest add https://ui.bld8.dev/r/example-navigation-nested.jsonComplete source
/*!
MIT License
Copyright (c) 2026 Jaison
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import { useState } from 'react';
import { Button, Checkbox } from '@bld8/ui/core';
import { NavigationMenu, NavigationMenuList, NavigationMenuItem, NavigationMenuTrigger, NavigationMenuContent, NavigationMenuLink, NavigationMenuGroup, NavigationMenuPopup, NavigationMenuViewport } from '@bld8/ui/navigation-menu';
export function NestedNavigationExample() {
const [section, setSection] = useState<string | null>(null);
return <div style={{ width: '100%', display: 'grid', gap: 20 }}>
<NavigationMenu aria-label="Library directory" value={section} onValueChange={setSection}>
<NavigationMenuList><NavigationMenuItem value="library"><NavigationMenuTrigger>Library</NavigationMenuTrigger><NavigationMenuContent>
<NavigationMenu orientation="vertical" defaultValue="foundations" className="bui-navigation-inline">
<NavigationMenuList>
<NavigationMenuItem value="foundations"><NavigationMenuTrigger>Foundations</NavigationMenuTrigger><NavigationMenuContent>
<NavigationMenuGroup label="Build a foundation">
<NavigationMenuLink href="#nav-nested-tokens" description="Shared colours, dimensions and motion.">Design tokens</NavigationMenuLink>
<NavigationMenuLink href="#nav-nested-inputs" description="Labels, validation and native forms.">Form controls</NavigationMenuLink>
</NavigationMenuGroup>
</NavigationMenuContent></NavigationMenuItem>
<NavigationMenuItem value="workflows"><NavigationMenuTrigger>Workflows</NavigationMenuTrigger><NavigationMenuContent>
<NavigationMenuGroup label="Complete an activity">
<NavigationMenuLink href="#nav-nested-review" description="Review records and recover failed saves.">Record review</NavigationMenuLink>
<NavigationMenuLink href="#nav-nested-upload" description="Send files with progress and cancellation.">Upload queue</NavigationMenuLink>
</NavigationMenuGroup>
</NavigationMenuContent></NavigationMenuItem>
<NavigationMenuItem value="archive"><NavigationMenuTrigger disabled>Archive</NavigationMenuTrigger></NavigationMenuItem>
</NavigationMenuList>
<NavigationMenuViewport />
</NavigationMenu>
</NavigationMenuContent></NavigationMenuItem></NavigationMenuList>
<NavigationMenuPopup popupProps={{ 'aria-label': 'Library destinations' }} />
</NavigationMenu>
<p role="status">{section ? 'Open directory: Library' : 'Directory closed'}</p>
<Button variant="secondary" onClick={() => setSection(null)} disabled={!section}>Close directory</Button>
<div className="bui-hint" style={{ display: 'grid', gap: 12 }}>
<p id="nav-nested-tokens">Design tokens keep surfaces, spacing and transition timing consistent.</p>
<p id="nav-nested-inputs">Form controls connect their labels, validation messages and submitted values.</p>
<p id="nav-nested-review">Record review keeps failed drafts available for retry.</p>
<p id="nav-nested-upload">Upload queues expose actual progress, cancellation and per-file retry.</p>
</div>
</div>;
}