Skip to content

Navigation Menu

A site-navigation bar where some items reveal a panel of links (Radix Navigation Menu). Plain items are ordinary links; panel items are disclosures.

<script>
import NavigationMenu from "@invisible-ui/svelte/NavigationMenu.svelte";
</script>

In Elements, assign the items as a property:

<ds-navigation-menu label="Site"></ds-navigation-menu>
<script type="module">
document.querySelector("ds-navigation-menu").items = [
{ value: "home", label: "Home", href: "/" },
{
value: "products",
label: "Products",
links: [{ label: "Catalog", href: "/catalog", description: "Every table in one place" }],
},
];
</script>

In React, value names the open panel, initially or controlled, and onValueChange reports what the user opens:

<NavigationMenu
label="Main"
items={[
{ value: "products", label: "Products", links: [{ label: "Analytics", href: "/analytics" }] },
{ value: "pricing", label: "Pricing", href: "/pricing" },
]}
onValueChange={(value) => track(value)}
/>
PropTypeDefaultDescription
label *string—Accessible name for the <nav> landmark.
items *NavigationMenuItem[]—Links ({ value, label, href }) or panels ({ value, label, links }).
onValueChange((value: string | null) => void) | undefinedundefinedCalled when the open panel changes.

Every href is rendered as given: pass only URLs you trust or have sanitized. See Security.

A panel link is { label, href, description?, current? }, and a plain link item accepts current? as well. Set current: true on the one link that leads to the page on screen.

  • A <nav> landmark containing links and disclosure buttons (aria-expanded / aria-controls → a labelled content panel). At most one panel is open.
  • The pointer resting on a trigger opens its panel while the pointer stays: after a short delay, or at once while another panel is open. Leaving the trigger and the panel closes it after a short delay.
  • A click, a tap, Enter or Space keeps the panel open, also one the pointer opened, and a second press closes it. A click has no delay and no time limit. ArrowDown opens the panel, keeps it open and moves focus to its first link. Escape closes it and returns focus to the trigger; an outside press closes it without moving focus. After a panel is closed by a press or Escape, hover opens it again only once the pointer has left the trigger. Positioning (flip/shift) is handled by the adapter.
  • Activating a link closes the open panel before the browser follows the link. Focus is not returned to the trigger: the page you open decides where focus goes. Only when focus would be lost (on the page body) and the trigger is still there does focus go back to the trigger.
  • The current page: the link marked current gets aria-current="page" and a visible mark that does not rely on colour alone (an underline at the top level, a bar along the start edge in a panel). The trigger whose panel holds it shows the same mark on screen but is never announced as current.
  • Assistive technology: not tested.
<NavigationMenu
label="Main"
items={[
{ value: "products", label: "Products", links: [
{ label: "Analytics", href: "/analytics", description: "Understand traffic." },
] },
{ value: "pricing", label: "Pricing", href: "/pricing" },
]}
/>

Themeable via --ds-navmenu-*.