# Navigation & Mega Menu

## Navigation & Mega Menu

**Files:** `src/config/menu.<lang>.json` · **Skill level:** Beginner

The header menu is built from one file per language. You write the links, and the theme handles the dropdown panel, the mega menu, the flyouts, the mobile menu, and keyboard support. For the header layouts and the header button, see [Header](/covena/customization/header/). For the footer menus, see [Menus](/covena/customization/menus/).

### How The Menu Behaves
On screens 1024 px wide and up:

- Every dropdown and the mega menu share one floating panel. Moving from one menu to the next, the panel changes size and position instead of closing and opening again.
- Hovering opens a menu, and moving away closes it after a short pause. A click or a key opens it too.
- A nested item in a dropdown opens a flyout beside its list. A flyout that would run off the screen opens on the other side.
- The menu item of the section you are in is marked as active.

Below 1024 px, the menu is a panel that slides in from the side. Dropdowns and the mega menu open inside it as accordions, and the panel ends with the consultation button, your phone and email, and the language menu. Focus stays inside the panel while it is open, and the page behind it doesn't scroll.

In Arabic the menus mirror. See [RTL & Arabic](/covena/features/rtl-arabic/).

### The Menu File
The header menu is the `headerPrimary` list in `src/config/menu.en.json`, and the same list in `menu.fr.json` and `menu.ar.json`. Items show in the order of the file.

**1. A plain link**

```json
{ "enable": true, "name": "Contact", "weight": 7, "url": "/contact/" }
```

**2. A dropdown.** Set `"hasChildren": true` and list the links in `children`, as in "Firm". A child with its own `"hasChildren": true` and `children` opens a flyout:

```json
{
  "enable": true,
  "name": "Firm",
  "weight": 5,
  "hasChildren": true,
  "children": [
    { "enable": true, "name": "About", "url": "/about/" },
    { "enable": true, "name": "Our history", "url": "/history/" },
    { "enable": true, "name": "Careers", "url": "/careers/" }
  ]
}
```

**3. A mega menu.** Set `"hasMegaMenu": true` and list groups of links in `menus`, as in "Practice areas". Each group is a column with its name on top. Each link can have a one-line `description`. `bar` adds a row of links along the bottom of the panel:

```json
{
  "enable": true,
  "name": "Practice areas",
  "weight": 2,
  "hasMegaMenu": true,
  "menus": [
    {
      "enable": true,
      "name": "For businesses",
      "children": [
        {
          "enable": true,
          "name": "Employment",
          "description": "Contracts, dismissals and settlement agreements",
          "url": "/practice-areas/employment/"
        }
      ]
    }
  ],
  "bar": {
    "enable": true,
    "links": [
      { "enable": true, "name": "All practice areas", "url": "/practice-areas/" },
      { "enable": true, "name": "Industries we serve", "url": "/industries/" }
    ]
  }
}
```

The mega menu is text only: it has no icons, images, or card. The demo has three groups: For businesses, For individuals, and Disputes & injury.

### Menu Fields
| Field | Used on | What it does |
| --- | --- | --- |
| `enable` | Everything | `true` shows the item, `false` hides it without deleting it |
| `name` | Everything | The text shown |
| `weight` | Top-level items | A position number. Keep it in step with the order in the file |
| `url` | Links | `/fees/` for your own pages (the language prefix is added for you), or a full `https://` address, which opens in a new tab |
| `hasChildren` | Dropdowns, flyouts | `true` when the item has `children` |
| `children` | Dropdowns, mega groups | The links inside |
| `hasMegaMenu` | Top-level items | `true` when the item opens a mega menu |
| `menus` | Mega menus | The groups of links. Each has `enable`, `name`, and `children` |
| `description` | Mega menu links | A short line under the link |
| `bar` | Mega menus | `enable`, an optional `text`, and `links`, each with `enable`, `name`, and `url` |

<Aside type="caution">
  Change the menu file of **every language** when you add or remove a link, so
  the menus stay in step. JSON is strict: a missing comma, or a comma after the
  last item, stops the site from building. Adding a menu item doesn't create its
  page.
</Aside>

### Keyboard Support
This works with no setup.

| Key | What it does |
| --- | --- |
| <kbd>Enter</kbd>, <kbd>Space</kbd>, or <kbd>↓</kbd> | Opens the menu on the focused item and moves to its first link. <kbd>↑</kbd> moves to its last link |
| <kbd>←</kbd> and <kbd>→</kbd> on the menu bar | Move between the top-level items |
| <kbd>↓</kbd> and <kbd>↑</kbd> in a panel | Move through the links |
| <kbd>→</kbd> on a nested item | Opens its flyout. <kbd>←</kbd> or <kbd>Escape</kbd> goes back one level |
| <kbd>Home</kbd> and <kbd>End</kbd> | Jump to the first or last item |
| <kbd>Tab</kbd> | Moves into the open panel, and out of it after the last link |
| <kbd>Escape</kbd> | Closes the menu and returns focus to the item that opened it |

In Arabic, the left and right arrows swap. In the mobile panel, <kbd>Escape</kbd> closes the panel and returns focus to the menu button.

### Files For Developers
| File | What it does |
| --- | --- |
| `src/layouts/components/global/header/Navbar.astro` | The menu, on desktop and in the mobile panel |
| `src/layouts/components/global/header/MenuItem.astro` | One top-level item |
| `src/layouts/components/global/header/NavStage.astro` | The shared desktop panel and its script |
| `src/layouts/components/global/header/NavStageDropdown.astro`, `NavStageList.astro` | Dropdown content and its nested lists |
| `src/layouts/components/global/header/NavStageMega.astro` | The desktop mega menu |
| `src/layouts/components/global/header/DropdownMenu.astro`, `MegaMenu.astro` | Accordions in the mobile panel |
| `src/layouts/components/widgets/Offcanvas.astro`, `HeaderOffcanvasContent.astro` | The mobile panel |
| `src/styles/navigation.css` | The menu styles |
| `src/lib/utils/navigationActive.ts` | Marks the current page in the menu |

### Do It With AI
```text
Add a practice area link to the Covena mega menu. In every src/config/menu.<lang>.json,
in the "Practice areas" item of headerPrimary, add { "enable": true, "name": "[NAME]",
"description": "[ONE LINE]", "url": "/practice-areas/[SLUG]/" } to the group "[GROUP]".
Translate the name and description for each language. Keep the item shape the same and
don't change the components. Then run npm run astro-check.
```