Getting StartedIntroduction SOONInstallation SOONChange log SOONRoadmap SOON
Components
ContainerFlex SOONGrid SOONSticky SOONSeparator SOONAspect Ratio SOONVisually Hidden SOON
DialogPopover SOONTooltipDropdown Menu SOONContext Menu SOONHover Card SOON
Link SOONNavigation Menu SOONBreadcrumbs SOONPagination SOONStepper SOON
Collapsible SOONAccordion SOONTabs SOON
H1 SOONH2 SOONH3 SOONH4 SOONH5 SOONH6 SOONP SOONSpan SOONEm SOONI SOONStrong SOONB SOONQ SOONBlockquote SOONUl SOONOl SOONKbd SOONCode SOONTable of Contents SOON
Icon SOONAvatar SOONAvatar Group SOONImage SOONVideo SOON
Notification SOONNotification Panel SOONToast SOONAlert SOON
Spinner SOONProgress Bar SOON
Button SOONBurger Button SOONButton Group SOON
Article Preview SOONBadge SOONCard SOONCommand Line SOONTable SOONTag SOONTag Group SOONTag Picker SOONTestimonial SOONProduct Tile SOONSkeleton SOONStatistic SOON
Address Input SOONCheckbox SOONCalendar Input SOONCalendar Range Input SOONColor Picker SOONCurrency Input SOONCredit Card Input SOONDate Input SOONDate Picker SOONDate Range Input SOONDate Range Picker SOONFieldset SOONFile Input SOONFile Dropzone SOONFile Picker SOONLabel SOONPin Input SOONPhone Number Input SOONRadio Button SOONRadio Group SOONRange Slider SOONRating SOONSearch Input SOONSwitch SOONSegmented Control SOONSelect SOONSlider SOONText Input SOONTextarea SOONToggle SOONToggle Group SOONURL Input SOON
TBD SOON

Navigation Menu

A collection of links for navigating websites.

NavigationMenu should not be confused with DropDownMenu or ContextMenu, although this primitive shares the name menu in the colloquial sense to refer to a set of navigation links, it does not use the WAI-ARIA menu role. This is because menu and menubars behave like native operating system menus most commonly found in desktop application windows, as such they feature complex functionality like composite focus management and first-character navigation.

These features are often considered unnecessary for website navigation and at worst can confuse users who are familiar with established website patterns.

See the W3C Disclosure Navigation Menu example for more information.

Features

Keyboard interactions

PropTypeDefault
SpaceWhen focus is on NavigationMenuTrigger, opens the content.
EnterWhen focus is on NavigationMenuTrigger, opens the content.
ArrowDownWhen horizontal and focus is on an open NavigationMenuTrigger, moves focus into NavigationMenuContent. Moves focus to the next NavigationMenuTrigger or NavigationMenuLink.
ArrowUpMoves focus to the previous NavigationMenu.Trigger or NavigationMenuLink.
ArrowRightWhen vertical and focus is on an open NavigationMenuTrigger, moves focus into its NavigationMenuContent. Moves focus to the next NavigationMenuTrigger or NavigationMenuLink.
ArrowLeftWhen vertical and focus is on an open NavigationMenuTrigger, moves focus into its NavigationMenuContent. Moves focus to the previous NavigationMenuTrigger or NavigationMenuLink.
HomeMoves focus to the first NavigationMenuTrigger or NavigationMenuLink.
EndMoves focus to the last NavigationMenuTrigger or NavigationMenuLink.
EscCloses open NavigationMenuContent and moves focus to its NavigationMenuTrigger.

Parts and their API

NavigationMenu

Contains all the parts of a navigation menu.

Props

PropTypeDefaultDescription
defaultValuestringNo default valueThe default value of the menu.
valuestringNo default valueThe value of the menu.
onValueChangefunctionNo default valueThe callback when the value changes.
delayDurationnumber200The delay duration in milliseconds.
skipDelayDurationnumber300The skip delay duration in milliseconds.
direnum: "ltr" | "rtl"No default valueThe direction of the menu.
orientationenum: "horizontal" | "vertical""horizontal"The orientation of the menu.

Usage

NavigationMenuExample.tsx
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
<NavigationMenu>
<NavigationMenuItem>
<NavigationMenuLink href="https://www.google.com" target="_blank">
Google
</NavigationMenuLink>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger className="group">
Learn <Icon name="chevron-down" className="relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180" aria-hidden="true" />
</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink href="https://www.google.com" target="_blank">
Wow dude, amazing!
</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuItem>
<NavigationMenuTrigger className="group">
Overview <Icon name="chevron-down" className="relative top-[1px] ml-1 h-3 w-3 transition duration-200 group-data-[state=open]:rotate-180" aria-hidden="true" />
</NavigationMenuTrigger>
<NavigationMenuContent>
<NavigationMenuLink href="https://www.google.com" target="_blank">
AndreCasal is a boss
</NavigationMenuLink>
</NavigationMenuContent>
</NavigationMenuItem>
<NavigationMenuIndicator className="top-full z-[1] flex h-[10px] items-end justify-center overflow-hidden transition-[width,transform_250ms_ease] data-[state=visible]:animate-in data-[state=hidden]:animate-out">
<div className="relative top-[60%] h-[10px] w-[10px] rotate-[45deg] rounded-tl-[2px] border bg-background shadow-lg" />
</NavigationMenuIndicator>
</NavigationMenu>

Here's the <NavigationMenu /> component in action.

Source

navigation-menu.tsx
  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
import { forwardRef } from 'react'
import { ListBox, ListBoxItem, type ListBoxItemProps, type ListBoxProps } from 'react-aria-components'
import { cn } from '#app/utils/tailwind-merge'
const NavigationMenu = forwardRef<HTMLDivElement, ListBoxProps<any>>(({ className, orientation = 'horizontal', ...props }, ref) => {
return <ListBox ref={ref} renderEmptyState={() => 'Add items to the navigation menu.'} orientation={orientation} className={cn('navigation-menu', className)} {...props} />
})
NavigationMenu.displayName = 'NavigationMenu'
const NavigationMenuItem = forwardRef<HTMLDivElement, ListBoxItemProps>((props, ref) => <ListBoxItem ref={ref} {...props} />)
NavigationMenuItem.displayName = 'NavigationMenuItem'
export { NavigationMenu, NavigationMenuItem }