Introducing PrimeReact v11-alpha 🎉Discover Now

useNavigationMenu

Hook that coordinates multiple useMenu instances inside a horizontal navigation bar with sibling traversal and single-open-at-a-time behavior.

basic-demo

Usage#

import { useMenu } from '@primereact/headless/menu';
import { useNavigationMenu } from '@primereact/headless/navigationmenu';
const navigationmenu = useNavigationMenu();
const fileMenu = useMenu({ navigationmenu, navigationmenuMenuId: 'file' });
const editMenu = useMenu({ navigationmenu, navigationmenuMenuId: 'edit' });

useNavigationMenu tracks which child menu is currently open and switches between them on hover or arrow-key traversal. Each useMenu registered to the bar surrenders its open-state to the navigation menu via the navigationmenu / navigationmenuMenuId props.

See Primitive for a component-based API.

Features#

  • Single-open-at-a-time — only one child menu may be open; opening another auto-closes the previous
  • Hover-to-switch — moving the pointer onto a sibling trigger while a menu is open transfers focus and open state
  • Arrow-key traversal — focusSibling lets child menus route arrow keys across triggers
  • Instant transition signal — registerInstantSignal enables animation-less hand-off when switching siblings
  • Horizontal or vertical orientation — exposed via aria-orientation and data-orientation

API#

useNavigationMenu#

NameTypeDefault
orientationNavigationMenuOrientation'horizontal'
The orientation of the navigationmenu. Determines which arrow keys move between triggers.
loopFocusbooleantrue
Whether keyboard focus loops back to the first/last item at the end of the list.
modalbooleantrue
Whether the navigationmenu is modal. When true, opening one menu prevents page interaction outside that menu.
disabledbooleanfalse
Whether all menus in the navigationmenu are disabled.

Returned values#

PropertyDescription
rootPropsProps for the navigation menu container (role="menubar", ARIA + data attributes)
state.openMenuIdId of the currently open child menu, or null
state.hasOpenMenuWhether any child menu is currently open
isMenuOpen(id)Returns true when the menu with the given id is the active one
onMenuOpenChangeCallback used by child useMenu to report open-state changes back to the bar
focusSibling(currentMenuId, 'next' | 'previous') — moves focus to the adjacent trigger
setPendingFocusMarks a sibling for focus after the current menu closes
registerTriggerUsed by child menus to register their trigger DOM ref for keyboard navigation

Accessibility#

NavigationMenu exposes role="menubar" and reflects orientation via aria-orientation. Each child trigger participates in arrow-key navigation.

Keyboard Support#

KeyFunction
left arrow / right arrowMoves focus to the previous / next trigger (horizontal orientation).
up arrow / down arrowMoves focus to the previous / next trigger (vertical orientation).
enter / spaceOpens the focused menu.
home / endMoves focus to the first / last trigger.
escapeCloses the open menu and returns focus to its trigger.