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:
npx @vinish/ui add navigation-menuimport { NavigationMenu, NavigationMenuItem, NavigationMenuLink, NavigationMenuGrid, NavigationMenuCard } from "@/components/vin/navigation-menu";import NavigationMenu, { NavigationMenuItem, NavigationMenuLink, NavigationMenuGrid, NavigationMenuCard } from "@/components/vin/navigation-menu.vue";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.
| Prop | Values | Default | In HTML |
|---|---|---|---|
labelName for the navigation, read by screen readers. | string | — | aria-label on nav.vin-nav-menu |
NavigationMenuItemA 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] |
NavigationMenuLinkA top-level link. active marks the current page. | { href, active } | — | li.vin-nav-menu__item > a.vin-nav-menu__link[aria-current=page] |
NavigationMenuGridThe panel's links in two columns, or one with list. | { list } | — | ul.vin-nav-menu__grid (.vin-nav-menu__grid--list) |
NavigationMenuCardA 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, Svelte | HTML 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".
Customize
Saved in this browser. Style and accent are in the header.