NavMenu
A hand-drawn dropdown of site-navigation links triggered by a button.
Overview
A NavMenu groups related pages behind one header trigger — e.g. “Design” revealing Design Style,
Foundations, Design Principles and UX Writing. Every entry is a real link, so visitors keep native link
behaviour: open in new tab, copy link address, and crawlers can follow them.
It is the navigation counterpart of Menu. Menu is an
action menu (role="menu", for commands like Edit / Delete); NavMenu is a disclosure of links and
deliberately uses no menu roles, which the ARIA Authoring Practices reserve for command sets. For a whole
navigation bar with several groups, NavigationMenu / gh-navigation-menu renders the full row.
Anatomy
A <button aria-expanded aria-controls> trigger shows and hides a floating panel. The panel holds a plain
list — <ul> / <li> — of <a href> links. There is no role="menu", role="menuitem" or
aria-haspopup="menu" anywhere. The trigger is a sketchy box (@ghds/sketch-core) and the panel reuses the
comp.menu.* tokens, so it looks like Menu. Data-driven — pass an items array of { href, label }.
Variants & States
| State | Status | Notes |
|---|---|---|
| Closed | Implemented | Default; aria-expanded=false, links hidden. |
| Open | Implemented | Panel shown; focus stays on the trigger unless opened with an Arrow key. |
| Highlighted link | Implemented | The hovered or focused link is highlighted. |
| Current page | Implemented | With current set, the matching link gets aria-current="page" and the trigger is underlined. |
| Disabled | Not implemented | Not supported; omit links that are unavailable. |
Usage
Do
- Use it in a site header to group related pages under one trigger.
- Wrap the header triggers in a <nav> landmark with an aria-label.
- Keep link labels short page names.
Don't
- Don't use it for actions (Edit, Delete) — use Menu.
- Don't nest groups inside the panel; it is one level deep.
- Don't hide the only route to an important page inside a dropdown.
Accessibility
- React / Web Components: disclosure pattern — the trigger has
aria-expandedandaria-controlspointing at the panel. Links are in the natural Tab order (no rovingtabindex). Arrow keys are an optional shortcut on top of Tab. Escape closes and returns focus to the trigger; clicking outside or tabbing out of the component closes it. Activating a link navigates natively. - Current page: pass
current(the page path) so the matching link carriesaria-current="page"and screen readers announce it as the current page. - React Native: no NavMenu — use
NavigationMenufrom@ghds/react-native. - See the Accessibility Guide.
| Key | Action |
|---|---|
Enter / Space | On the trigger: open or close the panel. |
↓ / ↑ | On the trigger: open and focus the first / last link. |
Tab / Shift+Tab | Move through the links; leaving the component closes it. |
Arrow Up / Down | In the panel: move between links (wraps). |
Home / End | In the panel: focus the first / last link. |
Enter | On a link: follow it. |
Escape | Close and return focus to the trigger. |
Content
The trigger names the group (“Design”, “Components”); links use page titles.
Props API
React@ghds/react
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Trigger button text. |
items | NavMenuItem[] | — | { href, label } per link. Each renders a real <a href>. |
current | string | — | Active page path. The exact-match link gets aria-current="page"; the trigger is underlined when a link is the current path or its ancestor. Query, hash and trailing slash are ignored. |
id | string | — | Trigger id; the panel id is derived from it. |
Web Components@ghds/web-components
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Trigger text (or slot custom trigger content). |
items | GhNavMenuItem[] | — | { href, label } per link (property, not attribute). |
current | string | — | Active page path; same matching as the React prop. |
Code examples
// React — @ghds/react
import { NavMenu } from '@ghds/react/nav-menu';
<nav aria-label="Main">
<NavMenu
label="Design"
items={[
{ href: '/design-style/', label: 'Design Style' },
{ href: '/foundations/', label: 'Foundations' },
{ href: '/principles/', label: 'Design Principles' },
{ href: '/ux-writing/', label: 'UX Writing' },
]}
/>
</nav>;
<!-- Web Components — @ghds/web-components -->
<script type="module">
import '@ghds/web-components/nav-menu';
// items is a property, not an attribute
document.getElementById('design').items = [
{ href: '/design-style/', label: 'Design Style' },
{ href: '/foundations/', label: 'Foundations' },
];
</script>
<nav aria-label="Main">
<gh-nav-menu id="design" label="Design"></gh-nav-menu>
</nav>