# NavigationMenu

A site header: a row of links, some of which are buttons that open a panel of more links. It is the **disclosure** pattern, not a menu: no `menu` roles, no arrow keys, Tab moves through everything. Each panel is a `<div popover>` next to its `<button popovertarget>`, so the browser gives the toggle, the expanded state, Escape, light dismiss and one open panel at a time with **no JavaScript**: the default NavigationMenu works before and without hydration, and its links are in the server HTML. After hydration the library closes a panel when focus leaves it and when one of its links is followed. A panel whose content is worth loading late opts into library mode, where opening is a transition.

## Anatomy

```tsx
import { NavigationMenu } from "@funstack/ui/navigation-menu";

<NavigationMenu.Root aria-label="Main">                          {/* nav */}
  <NavigationMenu.List>                                          {/* ul[role=list] */}
    <NavigationMenu.Item>                                        {/* li; owns one panel */}
      <NavigationMenu.Trigger>Products</NavigationMenu.Trigger>  {/* button[popovertarget] */}
      <NavigationMenu.Popup>                                     {/* div[popover=auto] */}
        <ul>
          <li><NavigationMenu.Link href="/analytics">Analytics</NavigationMenu.Link></li>
          <li><NavigationMenu.Link href="/billing">Billing</NavigationMenu.Link></li>
        </ul>
      </NavigationMenu.Popup>
    </NavigationMenu.Item>
    <NavigationMenu.Item>
      <NavigationMenu.Link href="/pricing" aria-current="page">Pricing</NavigationMenu.Link>
    </NavigationMenu.Item>
  </NavigationMenu.List>
</NavigationMenu.Root>
```

- **Render the Popup immediately after its Trigger**, in the same Item. Every engine then puts the panel's links right after the Trigger in the Tab order (Safari only when the two are adjacent). Development warns otherwise. One Trigger and one Popup per Item.
- **The Item owns the open state**, with the props of a [Popover.Root](popover.md). There is no state on the Root: the platform keeps the panels exclusive, because sibling `auto` popovers close each other.
- **Root and List are structure**: the `nav` landmark (name it when the page has more than one) and a list with an explicit `role="list"`, which keeps its list semantics in Safari under `list-style: none`. Neither has a `"use client"` directive; Item, Trigger, Popup and Link are client components with serialisable props, so the whole navigation can be written in a Server Component.
- An Item with only a Link in it is a plain `li`: a top-level entry.

```tsx title="NavigationMenuSite.tsx"
// No "use client": this file is a Server Component. No Item has an open-state prop, so every
// panel runs in JS-free mode: the browser toggles it through `popovertarget`, keeps one open at a
// time, closes it on Escape and a click outside, and the links are in the server HTML. After
// hydration the library adds two closes: focus leaving an Item, and a followed link.
//
// The links point at sections of this page, so following one keeps you here.
import { NavigationMenu } from "@funstack/ui/navigation-menu";

const sections = {
  Reference: [
    { href: "#anatomy", label: "Anatomy" },
    { href: "#props", label: "Props" },
    { href: "#data-attributes", label: "Data attributes" },
  ],
  Behaviour: [
    { href: "#how-it-works", label: "How it works" },
    { href: "#keyboard-and-aria", label: "Keyboard and ARIA" },
    { href: "#suspense", label: "Suspense" },
  ],
};

export function NavigationMenuSite() {
  return (
    <NavigationMenu.Root aria-label="This page" className="demo-nav">
      <NavigationMenu.List className="demo-nav-list">
        {Object.entries(sections).map(([title, links]) => (
          <NavigationMenu.Item key={title}>
            <NavigationMenu.Trigger className="demo-nav-trigger">{title}</NavigationMenu.Trigger>
            <NavigationMenu.Popup className="demo-nav-panel">
              <ul className="demo-nav-links">
                {links.map((link) => (
                  <li key={link.href}>
                    <NavigationMenu.Link href={link.href}>{link.label}</NavigationMenu.Link>
                  </li>
                ))}
              </ul>
            </NavigationMenu.Popup>
          </NavigationMenu.Item>
        ))}
        <NavigationMenu.Item>
          <NavigationMenu.Link href="#recipes" className="demo-nav-trigger">
            Recipes
          </NavigationMenu.Link>
        </NavigationMenu.Item>
      </NavigationMenu.List>
    </NavigationMenu.Root>
  );
}
```

```css title="navigation-menu.css"
/* NavigationMenu: a row of Triggers (button[popovertarget]) and links; each panel is an auto
   popover right after its Trigger. Open state is `:popover-open`; `data-open` on the Trigger
   after hydration, `:has(+ :popover-open)` before it. */

.demo-nav-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.demo-nav-trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.35em 0.8em;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--color-text);
  font: inherit;
  text-decoration: none;
  cursor: pointer;
}

.demo-nav-trigger:hover {
  background: var(--color-bg-secondary);
}

.demo-nav-trigger[data-open],
.demo-nav-trigger:has(+ :popover-open) {
  background: var(--color-bg-secondary);
  color: var(--color-link);
}

.demo-nav-trigger[data-pending] {
  cursor: progress;
}

.demo-nav-panel {
  /* The popover UA stylesheet sets `inset: 0; margin: auto`: reset both for anchored placement. */
  inset: auto;
  margin: 4px 0;
  min-inline-size: 12rem;
  padding: 6px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: var(--color-bg);
  color: var(--color-text);
  box-shadow: 0 12px 40px rgb(0 0 0 / 0.2);
  opacity: 0;
  translate: 0 -4px;
  transition:
    opacity 0.15s,
    translate 0.15s,
    display 0.15s allow-discrete,
    overlay 0.15s allow-discrete;
}

.demo-nav-panel:popover-open {
  opacity: 1;
  translate: 0;
}

@starting-style {
  .demo-nav-panel:popover-open {
    opacity: 0;
    translate: 0 -4px;
  }
}

::view-transition-group(.demo-nav-panel) {
  animation-duration: 0.2s;
}

.demo-nav-links {
  margin: 0;
  padding: 0;
  list-style: none;
}

.demo-nav-links a {
  display: block;
  padding: 0.35em 0.6em;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
}

.demo-nav-links a:hover,
.demo-nav-links a:focus-visible {
  background: var(--color-bg-secondary);
}

.demo-nav [aria-current="page"] {
  font-weight: 600;
}
```

This example is a Server Component. Open a panel and press Tab: focus enters the panel's links, and leaving the last one closes it. Opening the other panel closes the first one; Escape and a click outside close it too. The links point at sections of this page.

## How it works

An Item with none of `open`, `defaultOpen`, `openChangeAction` and `onOpenChange` runs in **JS-free mode**: the browser toggles the panel and the content is always mounted. Any of them selects **library mode**: the Trigger's click is a request awaited in the Item's transition, the content mounts on open, and the closes the browser performs are facts. The mode is fixed at mount, and the two can be mixed in one navigation.

| Close | Who | Library mode channel | \`reason\` |
| - | - | - | - |
| Trigger click while open | the browser (JS-free); the library (library mode) | `openChangeAction(false)`, awaited with the panel still shown | `"activate"` |
| A followed Link inside the panel | the library, after hydration | `openChangeAction(false)`, awaited | `"activate"` |
| Escape (focus returns to the Trigger) | the browser | `onOpenChange(false)` | `"dismiss"` |
| A press outside | the browser | `onOpenChange(false)` | `"dismiss"` |
| Another panel (or any other `auto` popover) opening | the browser | `onOpenChange(false)` | `"dismiss"` |
| Focus leaving the Item (Tab past the last link) | the library, after hydration | `onOpenChange(false)`; while the open is still pending, `openChangeAction(false)` | `"dismiss"` |
| Controlled `open={false}` | the library | none | – |

- **Opens on a click only** (Enter and Space are the native click), never on hover: touch has no hover, and a button that opens on hover and toggles on click closes the panel under a user who hovers and then clicks. A hover preview is a [HoverCard](hover-card.md).
- **Focus leaving the Item** to an element outside it closes the panel at once (a null `relatedTarget`, such as a window blur, closes nothing). Without it, a keyboard user who tabs past a panel would leave it open over the page. It needs the hydrated component; before hydration a panel stays open until Escape, a click outside or another panel.
- **Use JS-free mode for a site's navigation.** Library mode is for a panel whose content is worth loading late (recently viewed pages, an account panel) or whose open state the app needs to know.

## Links

```tsx
<NavigationMenu.Link href="/pricing" aria-current="page">Pricing</NavigationMenu.Link>
<NavigationMenu.Link render={<RouterLink to="/analytics" />}>Analytics</NavigationMenu.Link>
```

- **Following a Link inside a panel closes the panel**: a click with the primary button and no modifier key. With a client-side router the navigation keeps the `nav` mounted, and a click inside a popover is not a light dismiss, so the panel would otherwise stay over the new page. A Ctrl-, Cmd-, Shift- or Alt-click (new tab, new window, download) and a middle click leave it open, so several links can be opened from one panel. The link's own attributes are not read: a plain click on a `target="_blank"` or a `download` link closes the panel too. `closeOnActivate={false}` opts a link out.
- **The panel closes right away, not with the new page.** In library mode the close is a request that settles as soon as `openChangeAction(false)` does; with a router that renders the next page in a transition (FUNSTACK Router, for one), the panel is gone before a page that loads its data commits, in a commit (and, with `transition`, a view transition) of its own. In JS-free mode it is a `hidePopover()` in the click.
- The close listener is attached to the element, so `onClick` stays yours and a router link's own click handling runs untouched (also when it prevents the default). When the panel closes, the browser returns focus from the link to the Trigger; where focus goes after the navigation is the router's business.
- **The current page** is the native `aria-current="page"`, which you set (the library does not know the URL) and style with `[aria-current="page"]`. A router link that sets it itself works through `render`.
- A Link outside a panel renders an `<a>` and nothing else.

## Props

### `NavigationMenu.Root`

| Prop | Type | Default | Description |
| - | - | - | - |
| `className` | `string \| ((state: NavigationMenuRootState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuRootState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuRootState) => ReactNode)` | – | Content, or a function of the part's state. |
| `render` | `ReactElement \| ((props, state: NavigationMenuRootState) => ReactNode)` | – | Replace the default \<nav> (element form) or take over rendering (function form). |

- **State**: `NavigationMenuRootState` is empty.
- **Owned**: none: every `<nav>` prop passes through. Name it with `aria-label` or `aria-labelledby`.

No `"use client"`: it reads no context and calls no hook.

### `NavigationMenu.List`

| Prop | Type | Default | Description |
| - | - | - | - |
| `className` | `string \| ((state: NavigationMenuListState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuListState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuListState) => ReactNode)` | – | Content, or a function of the part's state. |
| `render` | `ReactElement \| ((props, state: NavigationMenuListState) => ReactNode)` | – | Replace the default \<ul> (element form) or take over rendering (function form). |

- **State**: `NavigationMenuListState` is empty.
- **Owned**: none. `role="list"` is a default you can override.

No `"use client"`.

### `NavigationMenu.Item`

| Prop | Type | Default | Description |
| - | - | - | - |
| `open` | `boolean` | – | Controlled open state of this Item's panel. Pass `onOpenChange` too: the browser closes the panel without asking (development warns). |
| `defaultOpen` | `boolean` | – | Initial open state in uncontrolled library mode. Shown after hydration, never in the server HTML. `defaultOpen={false}` alone selects library mode. |
| `openChangeAction` | `ChangeAction<boolean, NavigationMenuOpenChangeDetails>` | – | Requests only: the Trigger's toggle and a followed Link's close. Awaited in the Item's transition: the panel opens when it resolves and the content has rendered, and closes when a close resolves. May be a Server Function. A rejection reaches the nearest Error Boundary above the Item and the panel keeps its previous state. |
| `onOpenChange` | `UrgentChangeHandler<boolean, NavigationMenuOpenChangeDetails>` | – | Facts only: the panel was dismissed (Escape, a click outside, another panel opening, focus leaving the Item). Always `false`, with `reason: "dismiss"`. Called synchronously, outside any transition, not awaited. Controlled: set state directly here (`onOpenChange={setOpen}`). On a controlled Item with no `openChangeAction`, also a close by the Trigger or a followed Link: the library performs it at once and calls this with `"activate"` ([nothing waits](../concepts/action-props.md#urgent-open)); the Trigger does not open it (a development warning says so). |
| `className` | `string \| ((state: NavigationMenuItemState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuItemState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuItemState) => ReactNode)` | – | A Trigger and its Popup, or a Link. The function form receives the optimistic state. |
| `render` | `ReactElement \| ((props, state: NavigationMenuItemState) => ReactNode)` | – | Replace the default \<li> (element form) or take over rendering (function form). |

- **State**: `NavigationMenuItemState` is `{ open, pending }`; `open` is optimistic, both are `false` in JS-free mode. `NavigationMenuOpenChangeDetails` is `{ reason }` plus the virtual `event`: `"activate"` for the Trigger and a followed Link, `"dismiss"` for everything else, `"platform"` for a panel found open at hydration.
- **Owned**: `data-open` (optimistic) and `data-pending` on the `<li>`, in library mode only; JS-free mode renders neither (style the open Item with `:has(:popover-open)`).

The focus-leave listener is attached through the `ref`, so `onBlur` stays yours. Every `li` prop passes through.

### `NavigationMenu.Trigger`

| Prop | Type | Default | Description |
| - | - | - | - |
| `disabled` | `boolean` | `false` | Never opens. Native `disabled` on a `<button>`; with a link or component `render` in library mode, `aria-disabled` (still focusable). A click runs no `onClick`, a `render` element's included, and is cancelled; a `render` element's `disabled` disables the part too ([unavailable parts](../concepts/render.md#unavailable)). |
| `className` | `string \| ((state: NavigationMenuTriggerState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuTriggerState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuTriggerState) => ReactNode)` | – | Rendered from optimistic state; must not suspend. |
| `render` | `ReactElement \| ((props, state: NavigationMenuTriggerState) => ReactNode)` | – | Replace the default \<button> (element form) or take over rendering (function form). It should stay a `<button>`: only a button is a `popovertarget` invoker (another element works only in library mode). |

- **State**: `NavigationMenuTriggerState` is `{ open, pending, disabled }` (Popover.Trigger's). In JS-free mode `state.open` is `false` (React holds no value) while `data-open` follows the panel, written from its `toggle` event.
- **Owned**: `type`, `disabled`, `popoverTarget`, `aria-expanded` (never rendered on a button: the browser exposes the panel's state on its invoker), `onClick` in library mode, `data-open`, `data-pending`, `data-disabled`; `commandfor`, `command` and `popoverTargetAction` are not accepted.

### `NavigationMenu.Popup`

| Prop | Type | Default | Description |
| - | - | - | - |
| `side` | `"top" \| "bottom" \| "left" \| "right" \| "inline-start" \| "inline-end" \| null` | `"bottom"` | Placement against the Trigger through inline `position-area`, with `position-try-fallbacks` flipping it when it does not fit. `null` renders no placement (and no `data-side` / `data-align`), for a full-width panel your stylesheet places. |
| `align` | `"start" \| "center" \| "end"` | `"start"` | Alignment along the side; `start` / `end` are inline-relative on a top or bottom side (mirrored in RTL). |
| `keepMounted` | `boolean` | `false` | Library mode: keep the children rendered inside a hidden `<Activity>` while the panel is closed. Ignored in JS-free mode, where they are always mounted. |
| `transition` | `ViewTransitionClass` | – | Library mode only. The class of the `<ViewTransition>` around the panel; without it no boundary is rendered. A string animates its own Item's opens and closes that the library dispatched (the Trigger, a followed Link) and its own mount and unmount ([only as the top of what is inserted or removed](../concepts/transitions.md#mount-unmount)), in all engines; nothing else (not another panel, not an unrelated transition, not content that changes inside). A controlled `open` you change in your own transition needs a map keyed on `fsui-navigation-menu-open` / `fsui-navigation-menu-close` plus `addTransitionType` ([recipe](../concepts/transitions.md#controlled)). A type map is React's: it names every panel that has it and that a commit with its types reaches, and each plays the class; end it with `default: "none"` ([Type maps](../concepts/transitions.md#type-maps)). Dismissals animate with CSS only. Keep it static: changing it remounts the popup. Any value, `"none"` included, makes a mount or `<Activity>` reveal of the Popup inside a transition run the page cross-fade; a plain open does not. While a view transition runs, the popup's CSS transitions are cut for the library's own show or hide (a `@keyframes` animation is not, and a dismissal keeps its CSS exit). |
| `className` | `string \| ((state: NavigationMenuPopupState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuPopupState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuPopupState) => ReactNode)` | – | The panel's links. In library mode they render from committed state and may suspend. |
| `render` | `ReactElement \| ((props, state: NavigationMenuPopupState) => ReactNode)` | – | Replace the default \<div> (element form) or take over rendering (function form). |

- **State**: `NavigationMenuPopupState` is `{ open, side, align }`; `open` is committed (`false` in JS-free mode; `:popover-open` is the DOM truth); `side` / `align` are where the browser placed the panel while it is shown, your props otherwise.
- **Owned**: `id`, `popover` (`"auto"`), `data-side` / `data-align` (unless `side` is `null`).

No role: the disclosure pattern's panel is a plain region, and a `<div popover>` moves no focus when it opens. Pass `aria-label` and a `role` for a named region. `onToggle` and `onBeforeToggle` are not accepted; use a `ref`.

### `NavigationMenu.Link`

| Prop | Type | Default | Description |
| - | - | - | - |
| `closeOnActivate` | `boolean` | `true` | Inside a Popup: following the link (primary button, no modifier key) closes the panel. Ignored outside a Popup. |
| `className` | `string \| ((state: NavigationMenuLinkState) => string \| undefined)` | – | A class name, or a function of the part's state. |
| `style` | `CSSProperties \| ((state: NavigationMenuLinkState) => CSSProperties \| undefined)` | – | Inline style, or a function of the part's state. |
| `children` | `ReactNode \| ((state: NavigationMenuLinkState) => ReactNode)` | – | Content, or a function of the part's state. |
| `render` | `ReactElement \| ((props, state: NavigationMenuLinkState) => ReactNode)` | – | Replace the default \<a> (element form) or take over rendering (function form). A router's link component: `render={<Link to="/" />}`. |

- **State**: `NavigationMenuLinkState` is empty.
- **Owned**: none: every anchor prop passes through, `onClick` and `aria-current` included.

## Data attributes

| Attribute | On | Meaning |
| - | - | - |
| `:popover-open` | Popup | The panel is shown (DOM truth, every mode). |
| `data-open` | Trigger | Library mode: optimistic open state. JS-free mode: kept from the panel's `toggle` after hydration (use `:has(+ :popover-open)` before it). |
| `data-pending` | Trigger | Library mode: an open or a close is in flight. |
| `data-open` | Item | Library mode: optimistic open state of its panel. |
| `data-pending` | Item | Library mode: an open or a close is in flight. |
| `data-disabled` | Trigger | The `disabled` prop. |
| `data-side`, `data-align` | Popup | While shown: where the browser placed the panel (after any flip). Otherwise the requested placement. Absent with `side={null}`. |
| `[aria-current="page"]` | Link | Yours: the current page's link. |

## Keyboard and ARIA

| Key | Where | Behaviour |
| - | - | - |
| Tab / Shift+Tab | anywhere | The document's order: a Trigger, then its open panel's links, then the next entry. Tab past the last link closes the panel behind. |
| Enter / Space | Trigger | Toggles the panel; focus stays on the Trigger. |
| Enter | Link | Follows it; the panel closes. |
| Escape | Trigger or panel, panel open | Closes the panel; focus returns to the Trigger. |

- **Opening moves no focus**: the user who pressed Enter on "Products" is still on it, and Tab enters the panel. There is no `initialFocus`.
- **No arrow keys**, so the keyboard works the same before and after hydration. The Trigger has no `aria-expanded` and no `aria-controls`: every engine exposes the popover's expanded state on its `popovertarget` invoker.
- **Not a menu**: no `menu` / `menuitem` roles. The WAI ARIA Authoring Practices recommend the disclosure pattern for site navigation; an application menu of commands is a [Menu](menu.md).

## Transition types

Concept: [Transitions & ViewTransition](../concepts/transitions.md#transition-types)

Library mode: `fsui-navigation-menu` plus `fsui-navigation-menu-open` or `fsui-navigation-menu-close` for the Trigger's toggle and a followed Link's close. Dismissals are facts and start no transition. JS-free mode starts none. These types are public API: key a `transition` map on them, and add them with `addTransitionType` for a controlled change ([Transitions](../concepts/transitions.md#controlled)). A string `transition` is keyed on an internal per-instance type instead, which this component's own dispatch adds.

> **With a router's view transitions**
>
> A Link's close and a router's navigation are two transitions that commit separately. Where the router adds its own transition type (FUNSTACK Router's `navigation`) before it awaits the navigation, React may attach that type to the panel's close commit, the next transition to commit, and the page's commit then has none. If your page animation matches on that type, give the panel no `transition`. The router side is tracked in [#189](https://github.com/uhyo/funstack-ui/issues/189).

## Optimistic and pending

Concept: [Pending & optimistic state](../concepts/pending-and-optimistic.md)

Library mode: from the click the Trigger has `data-open` (optimistic) and `data-pending`; the panel is hidden until `openChangeAction(true)` resolves and its content has rendered. A close through the Trigger or a Link keeps the panel shown until `openChangeAction(false)` settles. Dismissals pend nothing.

```tsx title="NavigationMenuRecent.tsx"
"use client";
import { use, useState } from "react";
import { NavigationMenu } from "@funstack/ui/navigation-menu";
import type { NavigationMenuOpenChangeDetails } from "@funstack/ui/navigation-menu";
import { sleep } from "./fake-api.js";

// A library-mode Item: `openChangeAction` selects it. The panel's content reads a promise with
// `use()`, so the first open suspends: the Trigger shows data-open and data-pending, the panel
// appears when the pages have loaded, with a view transition (`transition`). Tab away while it
// loads and the open is cancelled. The first panel is JS-free; opening one closes the other.
let recent: Promise<readonly string[]> | null = null;
function loadRecent(): Promise<readonly string[]> {
  recent ??= sleep(1500).then(() => ["Quarterly report", "Invoices", "Team settings"]);
  return recent;
}

function RecentPages() {
  const pages = use(loadRecent());
  return (
    <ul className="demo-nav-links">
      {pages.map((page) => (
        <li key={page}>
          <NavigationMenu.Link href="#suspense">{page}</NavigationMenu.Link>
        </li>
      ))}
    </ul>
  );
}

export function NavigationMenuRecent() {
  const [log, setLog] = useState("(none yet)");
  const request = (open: boolean, { reason }: NavigationMenuOpenChangeDetails) => {
    setLog(`openChangeAction(${open}, "${reason}")`);
  };
  // A fact: Escape, a click outside, another panel opening, focus leaving the Item.
  const dismissed = (open: boolean, { reason }: NavigationMenuOpenChangeDetails) => {
    setLog(`onOpenChange(${open}, "${reason}")`);
  };
  return (
    <div className="demo-stack">
      <NavigationMenu.Root aria-label="Workspace" className="demo-nav">
        <NavigationMenu.List className="demo-nav-list">
          <NavigationMenu.Item>
            <NavigationMenu.Trigger className="demo-nav-trigger">Products</NavigationMenu.Trigger>
            <NavigationMenu.Popup className="demo-nav-panel">
              <ul className="demo-nav-links">
                <li>
                  <NavigationMenu.Link href="#suspense">Analytics</NavigationMenu.Link>
                </li>
                <li>
                  <NavigationMenu.Link href="#suspense">Billing</NavigationMenu.Link>
                </li>
              </ul>
            </NavigationMenu.Popup>
          </NavigationMenu.Item>
          <NavigationMenu.Item openChangeAction={request} onOpenChange={dismissed}>
            <NavigationMenu.Trigger className="demo-nav-trigger">
              {({ pending }) => (
                <>Recent{pending && <span className="demo-spinner" aria-hidden />}</>
              )}
            </NavigationMenu.Trigger>
            <NavigationMenu.Popup className="demo-nav-panel" transition="demo-nav-panel">
              <RecentPages />
            </NavigationMenu.Popup>
          </NavigationMenu.Item>
        </NavigationMenu.List>
      </NavigationMenu.Root>
      <p className="demo-readout">
        Last: <code>{log}</code>
      </p>
    </div>
  );
}
```

`navigation-menu.css`: the same file as above.

The first open of "Recent" waits 1.5 s for its pages: the Trigger shows a spinner, and the other panel stays open meanwhile. Tab away before it appears and the open is cancelled.

## Suspense

Concept: [Suspense](../concepts/suspense.md)

Library mode: the Popup's children render from committed state, so content that suspends holds the open, with `data-pending` on the Trigger, and the panel appears complete. In JS-free mode nothing suspends on open: the content is part of the page and streams with it.

```tsx
<NavigationMenu.Item openChangeAction={(open) => { if (open) preloadRecent(); }}>
  <NavigationMenu.Trigger>Recent</NavigationMenu.Trigger>
  <NavigationMenu.Popup transition="nav-panel">
    <RecentPages />  {/* use(recent): the Trigger is data-pending until it resolves */}
  </NavigationMenu.Popup>
</NavigationMenu.Item>
```

## Browser-owned state

Concept: [Browser-owned state](../concepts/browser-owned-state.md)

Each panel is an `auto` popover: the browser owns Escape, light dismiss and one panel at a time, and in JS-free mode the whole open state. In library mode a close the browser performs is a fact for `onOpenChange`; the focus-leave close is shaped the same way.

## Before hydration

Concept: [Server Components](../concepts/server-components.md#before-hydration)

JS-free mode works completely before hydration and without JavaScript: open, close, Escape, light dismiss, one panel at a time, the Tab order, placement and CSS animation. Missing until hydration: the focus-leave close and the Link close. A library-mode Trigger pressed before hydration opens an empty panel, which fills when the page hydrates.

## Recipes

### Animation, with and without JavaScript

```css
.nav-panel { opacity: 0; translate: 0 -4px; transition: opacity .15s, translate .15s, display .15s allow-discrete, overlay .15s allow-discrete; }
.nav-panel:popover-open { opacity: 1; translate: 0; }
@starting-style { .nav-panel:popover-open { opacity: 0; translate: 0 -4px; } }
.nav-trigger[data-open] { color: var(--accent); }             /* after hydration */
.nav-trigger:has(+ :popover-open) { color: var(--accent); }   /* without JavaScript */
[aria-current="page"] { font-weight: 600; }
```

### A full-width panel

```tsx
<NavigationMenu.Popup side={null} className="mega-panel">…</NavigationMenu.Popup>
```

```css
.mega-panel { position: fixed; inset-inline: 0; top: anchor(bottom); margin: 0; }
```

The implicit anchor (the Trigger) still applies. On small screens, put the same links in a different component, such as a [Drawer](drawer.md) or a [Collapsible](collapsible.md).

### With a router

Render the router's link component through `render`. Its click then navigates on the client, and the Link part still closes the panel. With `href` alone the element is a plain `<a>`, and the browser loads a new document. React Router:

```tsx
import { Link, useLocation } from "react-router";

function NavLink({ to, children }) {
  const { pathname } = useLocation();
  return (
    <NavigationMenu.Link
      render={<Link to={to} />}
      aria-current={pathname === to ? "page" : undefined}
    >
      {children}
    </NavigationMenu.Link>
  );
}
```

## Not included

- Opening on hover; arrow keys, Home and End between the top-level entries.
- A shared viewport that resizes between panels, an indicator under the active Trigger, an arrow, and a Root-level `value` naming the open Item: all need a Root-level owner. Moving from one panel to another is a dismissal and an open on two Items, so no single commit morphs one into the other.
- Nested flyouts (a panel inside a panel).
- A `current` prop on Link: use `aria-current="page"`.
