Skip to main content

Navigation Menu

View as Markdown

A collection of links and menus for website navigation.

<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>
typo3 ui:add navigationMenu

Read more about installing Components and Primitives.

Give an item a trigger and a content to open a dropdown right below it. Open Products or Company below.

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".

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.

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.

Provides shared navigation menu state and semantics. Renders a <nav> element.

NameDescriptionRequiredDefault
orientationEnum\Orientation
The orientation of the navigation menu.
No
Horizontal
defaultValuestring
The default value of the navigation menu. Use when you don't want to control the value of the menu.
No
''
openDelayinteger
The delay before the menu opens.
No
200
closeDelayinteger
The delay before the menu closes.
No
300
disableHoverTriggerboolean
Whether to disable the hover trigger.
No
-
disableClickTriggerboolean
Whether to disable the click trigger.
No
-
disablePointerLeaveCloseboolean
Whether to disable the pointer leave close.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
rootIdstring
The root ID of the component, used for hydration and identification.
No
-
idsarray
The IDs of of the component parts for composition.
No
[]
autoMountboolean
Whether the client initializes the component on its own. Set it to false to mount it yourself with `mount()`
No
true
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-root<uid>
data-orientationThe orientation of the navigation-menu

Groups the top-level navigation items. Renders a <ul> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-list<uid>
data-orientationThe orientation of the list

Wraps a single navigation item and its related parts. Renders an <li> element.

NameDescriptionRequiredDefault
valuestring
The value of the item.
Yes
-
disabledboolean
Whether the item is disabled.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-item<uid>
data-valueThe value of the item
data-state"open" | "closed"
data-orientationThe orientation of the item
data-disabledPresent when disabled

Opens and closes the related navigation content. Renders a <button> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-trigger<uid>
data-uid
data-trigger-proxy-id
data-valueThe value of the item
data-state"open" | "closed"
data-disabledPresent when disabled

Provides a hidden focus proxy for shared viewport behavior. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-trigger-proxy<uid>
data-trigger-proxy
data-trigger-id

Renders a navigational link item. Renders an <a> element.

NameDescriptionRequiredDefault
valuestring
The value of the item this link belongs to. By default this is inherited from the parent navigationMenu.item.
No
-
currentboolean
Whether the link is the current page.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-link<uid>
data-valueThe value of the item
data-currentPresent when current

Provides a track for the active-item indicator. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Displays the shared active-item indicator. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-indicator<uid>
data-state"open" | "closed"
data-orientationThe orientation of the indicator

Displays an indicator for an open item. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-item-indicator<uid>
data-state"open" | "closed"
data-orientationThe orientation of the item
data-valueThe value of the item

Contains the popup content for a navigation item. Renders a <div> element.

NameDescriptionRequiredDefault
valuestring
The value of the item this content belongs to.
No
-
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-content<uid>
data-state"open" | "closed"
data-orientationThe orientation of the content
data-valueThe value of the item
data-nestedPresent when the content is nested within another {{widget}}
data-has-nestedPresent when the content has nested {{widget}}s

Positions the shared viewport element. Renders a <div> element.

NameDescriptionRequiredDefault
alignEnum\NavigationMenuAlign
Placement of the viewport for CSS variables `--viewport-x` and `--viewport-y`.
No
Center
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-viewport-positioner<uid>
data-orientationThe orientation of the viewportpositioner
data-align

Displays the shared viewport that can host item content. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-viewport<uid>
data-state"open" | "closed"
data-orientationThe orientation of the viewport
data-align
data-nestedPresent when the viewport is nested within another {{widget}}
data-has-nestedPresent when the viewport has nested {{widget}}s

Provides a proxy element used to size and align the viewport. Renders a <span> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Displays a decorative arrow for the indicator or content. Renders a <div> element.

NameDescriptionRequiredDefault
attributesarray
Additional attributes that should be rendered on the component where ui:attributes is used.
No
[]
asChildboolean
If true the component uses its child only without the component template. Like Radix UI asChild or Base UI render props.
No
-
classstring
The CSS class(es) to be applied to the component.
No
-

Rendered data attributes

AttributeDescription
data-navigation-menu-arrow<uid>
data-orientationThe orientation of the arrow
NameTypeDescription
valuestring | nullThe current value of the menu
setValue(value: string) => voidSets the value of the menu
openbooleanWhether the menu is open
isViewportRenderedbooleanWhether the viewport is rendered
getViewportNode() => HTMLElement | nullGets the viewport node element
orientationOrientationThe orientation of the menu
repositionVoidFunctionFunction to reposition the viewport
getTriggerState(props: ItemProps) => TriggerStateReturns the state of a specific trigger
getContentState(props: ContentProps) => ContentStateReturns the state of a specific content
KeyDescription
ArrowDownWhen focus is on trigger (vertical orientation), moves focus to the next trigger.
ArrowUpWhen focus is on trigger (vertical orientation), moves focus to the previous trigger.
ArrowRightWhen focus is on trigger (horizontal orientation), moves focus to the next trigger.
When focus is on content, moves focus to the next link.
ArrowLeftWhen focus is on trigger (horizontal orientation), moves focus to the previous trigger.
When focus is on content, moves focus to the previous link.
HomeWhen focus is on trigger, moves focus to the first trigger.
When focus is on content, moves focus to the first link.
EndWhen focus is on trigger, moves focus to the last trigger.
When focus is on content, moves focus to the last link.