Components Navigation
Navigation menu
Group related destinations in keyboard-accessible disclosure menus.
Usage
Each group has a Label and a Links array of Label and Href pairs. Tab to a summary and press Enter or Space. The optional module adds Escape and outside-click dismissal.
Register navigation-menu with Head and pass its properties to Render. Go setup guide
Go usage
err := mono.UI.Render(w, "navigation-menu", mono.Props{
"Groups": []any{
map[string]any{
"Label": "Build",
"Links": []any{
map[string]any{
"Href": "/docs/using-vite.html",
"Label": "Using Vite",
},
map[string]any{
"Href": "/docs/using-the-cli.html",
"Label": "Using the CLI",
},
},
},
map[string]any{
"Label": "Explore",
"Links": []any{
map[string]any{
"Href": "/icons.html",
"Label": "Icons",
},
map[string]any{
"Href": "/docs.html",
"Label": "Documentation",
},
},
},
},
"Label": "Explore Mono",
})Rendered HTML
<nav data-mono="navigation-menu" id="demo-navigation-menu" class="mu-row" aria-label="Explore Mono">
<details name="demo-navigation-menu-group"><summary class="mu-btn mu-disclosure">Build</summary>
<ul class="mu-panel mu-list"><li><a class="mu-item" href="/docs/using-vite.html">Using Vite</a></li><li><a class="mu-item" href="/docs/using-the-cli.html">Using the CLI</a></li></ul>
</details><details name="demo-navigation-menu-group"><summary class="mu-btn mu-disclosure">Explore</summary>
<ul class="mu-panel mu-list"><li><a class="mu-item" href="/icons.html">Icons</a></li><li><a class="mu-item" href="/docs.html">Documentation</a></li></ul>
</details>
</nav>Go template
<nav data-mono="navigation-menu" id="{{.ID}}" class="mu-row" aria-label="{{.Label}}">
{{range .Groups}}<details name="{{$.ID}}-group"><summary class="mu-btn mu-disclosure">{{.Label}}</summary>
<ul class="mu-panel mu-list">{{range .Links}}<li><a class="mu-item" href="{{.Href}}">{{.Label}}</a></li>{{end}}</ul>
</details>{{end}}
</nav>Component CSS
[data-mono="navigation-menu"] { align-items:flex-start; flex-wrap:wrap; }
[data-mono="navigation-menu"] details { min-width:6rem; }
[data-mono="navigation-menu"] ul { margin:.35rem 0 0; padding:.3rem; }
[data-mono="navigation-menu"] a { display:block; padding:.45rem .55rem; color:inherit; }
[data-mono="navigation-menu"] a:hover { background:#eee; }JavaScript module
export function mount(root) {
for (const entry of root.querySelectorAll('details')) {
let controller;
entry.addEventListener('toggle', () => {
controller?.abort();
if (!entry.open) return;
controller = new AbortController();
document.addEventListener('pointerdown', event => {
if (!event.composedPath().includes(entry)) entry.open = false;
}, { signal: controller.signal });
});
entry.addEventListener('keydown', event => {
if (event.key !== 'Escape' || !entry.open) return;
event.preventDefault();
entry.open = false;
entry.querySelector('summary').focus();
});
}
}Use the HTML in a static site
Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.
Shared CSS Component CSS Ready-to-use module
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./navigation-menu.css">
<script type="module" src="./navigation-menu.js"></script>Copy into your project
Run this command from the Mono checkout. Set -out to the component directory in your application.
go run ./cmd/mono-ui add -out ./components navigation-menuExample properties (JSON)
{
"Groups": [
{
"Label": "Build",
"Links": [
{
"Href": "/docs/using-vite.html",
"Label": "Using Vite"
},
{
"Href": "/docs/using-the-cli.html",
"Label": "Using the CLI"
}
]
},
{
"Label": "Explore",
"Links": [
{
"Href": "/icons.html",
"Label": "Icons"
},
{
"Href": "/docs.html",
"Label": "Documentation"
}
]
}
],
"Label": "Explore Mono"
}