This documentation is under construction. Pages can be missing or change at any time. Follow it on GitHub.

Skip to content

Navigation Menu

A collection of links and menus for website navigation.

Examples#

Nested submenus#

A NavigationMenu can be nested within a higher-level NavigationMenuContent part to create a multi-level navigation menu.

Nested inline submenus#

For second-level navigation that should stay in the same panel, render only the NavigationMenuList and the NavigationMenuViewport of the nested menu (no positioner and no popup), with a defaultValue.

Large menus#

When you have large menu content that doesn’t fit in the viewport in some cases, you usually have two choices:

- Compress the navigation menu content: give the content and the popup max-height: var(--available-height), so the menu is more compact and does not overflow.

- Make the navigation menu scrollable: put the content in a Scroll Area, which keeps the scrollbars hidden while the content changes, and lets the arrow stay centered.

API reference#

Import the components of the family:

use Phem\Ui\NavigationMenu;
use function Phem\Ui\{NavigationMenuList, NavigationMenuItem, NavigationMenuTrigger, NavigationMenuIcon, NavigationMenuContent, NavigationMenuLink, NavigationMenuBackdrop, NavigationMenuPositioner, NavigationMenuPopup, NavigationMenuArrow, NavigationMenuViewport};

The links of a site, with a panel of links under some items: Base UI NavigationMenu.Root, on the phem-navigation-menu controller. The content of the open item moves into one shared popup, which animates its size between the items.

Put a NavigationMenuPositioner after the list, with a NavigationMenuPopup and a NavigationMenuViewport in it. The props of the Base UI Positioner are props of the root. The positioner goes in the top layer (popover="manual"), so it needs no Portal.

A NavigationMenu in a NavigationMenuContent is a submenu, as in Base UI: a <div> with the width of its place, and its arrow keys move the focus in the content of the parent menu.

PropTypeDefault
defaultValue?stringnull
delayint50
closeDelayint50
orientation'horizontal' | 'vertical'Orientation::Horizontal
side'top' | 'bottom' | 'left' | 'right' | 'inline-start' | 'inline-end'Side::Bottom
align'start' | 'center' | 'end'Align::Center
sideOffsetint10
alignOffsetint0
collisionPaddingint5
collisionPaddingInline?intnull
flipbooltrue
children?Htmlnull
...attrsarray[]

The list of the items of the navigation menu (<ul>).

PropTypeDefault
children?Htmlnull
...restmixed—

An item: a trigger with a content, or a link. value names the item.

PropTypeDefault
value?stringnull
children?Htmlnull
...restmixed—

The button that opens the content of its item. In the list, it has the look of a link of the list. In a content (a nested menu), it is a card: give it the card prop.

PropTypeDefault
cardboolfalse
children?Htmlnull
...restmixed—

The caret of a trigger. It turns when its content is open.

PropTypeDefault
children?Htmlnull
...restmixed—

The panel of an item. It moves into the viewport while it is open.

PropTypeDefault
children?Htmlnull
...restmixed—

A link. In the list, it has the look of a trigger. In a content, it is a card: give it the card prop. Give the link of the current page aria-current="page". It renders an <a>, so Turbo opens its page with client-side routing.

PropTypeDefault
href (required)string—
cardboolfalse
children?Htmlnull
...restmixed—

A layer under the popup of the navigation menu, while a content is open.

PropTypeDefault
...restmixed—

The box that goes next to the trigger of the open item. It shows in the top layer (popover="manual"): no overflow of an element around the menu cuts it.

PropTypeDefault
children?Htmlnull
...restmixed—

The box of the content. Its size animates between the items (--popup-width, --popup-height).

PropTypeDefault
children?Htmlnull
...restmixed—

The arrow of the popup, at the side of the active trigger.

PropTypeDefault
...restmixed—

The place of the open content in the popup.

PropTypeDefault
...restmixed—

The source of the examples: examples/ui/NavigationMenu.phem.

Phem
Esc
↑↓ to navigate↵ to openEsc to close