Navigation Menu
View as MarkdownA collection of links and menus for website navigation.
Features
Permalink to heading "Features"- Supports simple inline dropdowns and shared viewport layouts
- Keyboard navigation with arrow keys,
Home, andEnd - Supports trigger-based menus and direct navigation links in the same list
- Animated indicator and shared viewport support
- Supports horizontal and vertical orientation
<primitives:navigationMenu.root>
<primitives:navigationMenu.list>
<primitives:navigationMenu.item>
<primitives:navigationMenu.trigger />
<primitives:navigationMenu.content>
<primitives:navigationMenu.link />
</primitives:navigationMenu.content>
</primitives:navigationMenu.item>
<primitives:navigationMenu.item>
<primitives:navigationMenu.link />
</primitives:navigationMenu.item>
</primitives:navigationMenu.list>
</primitives:navigationMenu.root>
When using the shared viewport pattern, add the optional viewport-related parts:
<primitives:navigationMenu.root>
<primitives:navigationMenu.list>
<primitives:navigationMenu.item>
<primitives:navigationMenu.trigger />
<primitives:navigationMenu.triggerProxy />
<primitives:navigationMenu.viewportProxy />
</primitives:navigationMenu.item>
</primitives:navigationMenu.list>
<primitives:navigationMenu.indicator>
<primitives:navigationMenu.arrow />
</primitives:navigationMenu.indicator>
<primitives:navigationMenu.viewportPositioner>
<primitives:navigationMenu.viewport>
<primitives:navigationMenu.content>
<primitives:navigationMenu.link />
</primitives:navigationMenu.content>
</primitives:navigationMenu.viewport>
</primitives:navigationMenu.viewportPositioner>
</primitives:navigationMenu.root>
Installation
Permalink to heading "Installation"typo3 ui:add navigationMenu
Please copy the files manually from GitHub into your project.
Read more about installing Components and Primitives.
Examples
Permalink to heading "Examples"Add dropdowns to items
Permalink to heading "Add dropdowns to items"Give an item a trigger and a content to open a dropdown right below it. Open Products or Company below.
Use plain links
Permalink to heading "Use plain links"An item can hold a plain link. Set current="{true}" on the link of the page the visitor is on to render aria-current="page".
Build a mega menu
Permalink to heading "Build a mega menu"Set withViewport="{true}" on the root and place the content parts in one shared viewport. The panels share one animated surface and an indicator marks the open item. Open Products, then Company.
API Reference
Permalink to heading "API Reference"The following tables cover the available props of the Fluid Primitives. For a full list of available client side props and methods, see the Zag.js Machine API.
navigationMenu.root
Permalink to heading "navigationMenu.root"Provides shared navigation menu state and semantics. Renders a <nav> element.
| Name | Description | Required | Default |
|---|---|---|---|
orientation | Enum\OrientationThe orientation of the navigation menu. | No | Horizontal |
defaultValue | stringThe default value of the navigation menu. Use when you don't want to control the value of the menu. | No | '' |
openDelay | integerThe delay before the menu opens. | No | 200 |
closeDelay | integerThe delay before the menu closes. | No | 300 |
disableHoverTrigger | booleanWhether to disable the hover trigger. | No | - |
disableClickTrigger | booleanWhether to disable the click trigger. | No | - |
disablePointerLeaveClose | booleanWhether to disable the pointer leave close. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
rootId | stringThe root ID of the component, used for hydration and identification. | No | - |
ids | arrayThe IDs of of the component parts for composition. | No | [] |
autoMount | booleanWhether the client initializes the component on its own. Set it to false to mount it yourself with `mount()` | No | true |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-root | <uid> |
data-orientation | The orientation of the navigation-menu |
navigationMenu.list
Permalink to heading "navigationMenu.list"Groups the top-level navigation items. Renders a <ul> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-list | <uid> |
data-orientation | The orientation of the list |
navigationMenu.item
Permalink to heading "navigationMenu.item"Wraps a single navigation item and its related parts. Renders an <li> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the item. | Yes | - |
disabled | booleanWhether the item is disabled. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-item | <uid> |
data-value | The value of the item |
data-state | "open" | "closed" |
data-orientation | The orientation of the item |
data-disabled | Present when disabled |
navigationMenu.trigger
Permalink to heading "navigationMenu.trigger"Opens and closes the related navigation content. Renders a <button> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-trigger | <uid> |
data-uid | |
data-trigger-proxy-id | |
data-value | The value of the item |
data-state | "open" | "closed" |
data-disabled | Present when disabled |
navigationMenu.triggerProxy
Permalink to heading "navigationMenu.triggerProxy"Provides a hidden focus proxy for shared viewport behavior. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-trigger-proxy | <uid> |
data-trigger-proxy | |
data-trigger-id |
navigationMenu.link
Permalink to heading "navigationMenu.link"Renders a navigational link item. Renders an <a> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the item this link belongs to. By default this is inherited from the parent navigationMenu.item. | No | - |
current | booleanWhether the link is the current page. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-link | <uid> |
data-value | The value of the item |
data-current | Present when current |
navigationMenu.indicatorTrack
Permalink to heading "navigationMenu.indicatorTrack"Provides a track for the active-item indicator. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
navigationMenu.indicator
Permalink to heading "navigationMenu.indicator"Displays the shared active-item indicator. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-indicator | <uid> |
data-state | "open" | "closed" |
data-orientation | The orientation of the indicator |
navigationMenu.itemIndicator
Permalink to heading "navigationMenu.itemIndicator"Displays an indicator for an open item. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-item-indicator | <uid> |
data-state | "open" | "closed" |
data-orientation | The orientation of the item |
data-value | The value of the item |
navigationMenu.content
Permalink to heading "navigationMenu.content"Contains the popup content for a navigation item. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
value | stringThe value of the item this content belongs to. | No | - |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-content | <uid> |
data-state | "open" | "closed" |
data-orientation | The orientation of the content |
data-value | The value of the item |
data-nested | Present when the content is nested within another {{widget}} |
data-has-nested | Present when the content has nested {{widget}}s |
navigationMenu.viewportPositioner
Permalink to heading "navigationMenu.viewportPositioner"Positions the shared viewport element. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
align | Enum\NavigationMenuAlignPlacement of the viewport for CSS variables `--viewport-x` and `--viewport-y`. | No | Center |
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-viewport-positioner | <uid> |
data-orientation | The orientation of the viewportpositioner |
data-align |
navigationMenu.viewport
Permalink to heading "navigationMenu.viewport"Displays the shared viewport that can host item content. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-viewport | <uid> |
data-state | "open" | "closed" |
data-orientation | The orientation of the viewport |
data-align | |
data-nested | Present when the viewport is nested within another {{widget}} |
data-has-nested | Present when the viewport has nested {{widget}}s |
navigationMenu.viewportProxy
Permalink to heading "navigationMenu.viewportProxy"Provides a proxy element used to size and align the viewport. Renders a <span> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
navigationMenu.arrow
Permalink to heading "navigationMenu.arrow"Displays a decorative arrow for the indicator or content. Renders a <div> element.
| Name | Description | Required | Default |
|---|---|---|---|
attributes | arrayAdditional attributes that should be rendered on the component where ui:attributes is used. | No | [] |
asChild | booleanIf true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props. | No | - |
class | stringThe CSS class(es) to be applied to the component. | No | - |
Rendered data attributes
| Attribute | Description |
|---|---|
data-navigation-menu-arrow | <uid> |
data-orientation | The orientation of the arrow |
Machine JavaScript API
Permalink to heading "Machine JavaScript API"| Name | Type | Description |
|---|---|---|
value | string | null | The current value of the menu |
setValue | (value: string) => void | Sets the value of the menu |
open | boolean | Whether the menu is open |
isViewportRendered | boolean | Whether the viewport is rendered |
getViewportNode | () => HTMLElement | null | Gets the viewport node element |
orientation | Orientation | The orientation of the menu |
reposition | VoidFunction | Function to reposition the viewport |
getTriggerState | (props: ItemProps) => TriggerState | Returns the state of a specific trigger |
getContentState | (props: ContentProps) => ContentState | Returns the state of a specific content |
Accessibility
Permalink to heading "Accessibility"| Key | Description |
|---|---|
ArrowDown | When focus is on trigger (vertical orientation), moves focus to the next trigger. |
ArrowUp | When focus is on trigger (vertical orientation), moves focus to the previous trigger. |
ArrowRight | When focus is on trigger (horizontal orientation), moves focus to the next trigger. When focus is on content, moves focus to the next link. |
ArrowLeft | When focus is on trigger (horizontal orientation), moves focus to the previous trigger. When focus is on content, moves focus to the previous link. |
Home | When focus is on trigger, moves focus to the first trigger. When focus is on content, moves focus to the first link. |
End | When focus is on trigger, moves focus to the last trigger. When focus is on content, moves focus to the last link. |