Skip to content
VinUIComponentsNavigation Menu

Navigation Menu

A site's main links, with panels of related pages that open on hover, click or the keyboard. Same markup and props in every style: switch the style in the header to see it change.

Basic

Two panels and a plain link. Point at a button, click it, or focus it and press Enter or Down Arrow. In HTML, add data-vin-nav-menu and include vinui.js once.

Simple list

A panel with one column of links, for shorter menus.

Installation

React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:

Terminal
npx @vinish/ui add navigation-menu
React
import { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuGrid, NavigationMenuCard } from "@/components/vin/navigation-menu";
Vue
import NavigationMenu, { NavigationMenuItem, NavigationMenuLink, NavigationMenuGrid, NavigationMenuCard } from "@/components/vin/navigation-menu.vue";
Svelte
import NavigationMenu from "$lib/components/vin/navigation-menu.svelte";
import NavigationMenuCard from "$lib/components/vin/navigation-menu-card.svelte";
import NavigationMenuGrid from "$lib/components/vin/navigation-menu-grid.svelte";
import NavigationMenuItem from "$lib/components/vin/navigation-menu-item.svelte";
import NavigationMenuLink from "$lib/components/vin/navigation-menu-link.svelte";

The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.

Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.

API

From spec/navigation-menu.json, which every framework version is tested against.

PropValuesDefaultIn HTML
label
Name for the navigation, read by screen readers.
string—aria-label on nav.vin-nav-menu
NavigationMenuItem
A top-level button with a panel of links.
{ trigger: ReactNode, children }—li.vin-nav-menu__item > button.vin-nav-menu__trigger[aria-expanded][popovertarget] + .vin-nav-menu__panel[popover]
NavigationMenuLink
A top-level link. active marks the current page.
{ href, active }—li.vin-nav-menu__item > a.vin-nav-menu__link[aria-current=page]
NavigationMenuGrid
The panel's links in two columns, or one with list.
{ list }—ul.vin-nav-menu__grid (.vin-nav-menu__grid--list)
NavigationMenuCard
A link in a panel, with a title and an optional line of text.
{ href, title, children }—li > a.vin-nav-menu__card > .vin-nav-menu__card-title + .vin-nav-menu__card-text

Parts

React, Vue, SvelteHTML classes
<NavigationMenu><NavigationMenuItem><NavigationMenuLink><NavigationMenuGrid><NavigationMenuCard>.vin-nav-menu.vin-nav-menu__list.vin-nav-menu__item.vin-nav-menu__trigger.vin-nav-menu__link.vin-nav-menu__panel.vin-nav-menu__grid.vin-nav-menu__grid--list.vin-nav-menu__card.vin-nav-menu__card-title.vin-nav-menu__card-text

Accessibility

  • It's a nav landmark with a list of links and disclosure buttons, so links stay links and Tab reaches every one in order.
  • Each button says whether its panel is open (aria-expanded). Enter or Space opens and closes it; Down Arrow opens it on the first link.
  • Left and Right Arrow move between the top-level items; Up and Down Arrow move between the links in an open panel.
  • Escape closes the panel and puts focus back on its button. Moving focus or the pointer away closes it too, unless it was opened with a click.
  • Mark the link to the current page with aria-current="page".