Fragiola

API: components

NavigationMenu

A site's navigation of links and disclosed panels in one shared popup that resizes between them (APG disclosure navigation), in each framework.

A site's navigation: a list of links and of triggers that disclose panels of more links (a mega menu), opened by a hover or a press, in one shared popup whose size moves from panel to panel. It follows the WAI-ARIA APG disclosure navigation menu: each trigger is a button with aria-expanded, the links are plain links, and nothing takes the menu role. The hover, the shared popup, the size variables, the activation direction and the nested levels follow Base UI's NavigationMenu. A menu of commands is a Menu.

Site header
Gallery

Behaviour

  • Hover (mouse and pen): entering a Trigger opens its Content after delay (50 ms); while one is open, entering another Trigger switches at once. Leaving the Trigger and the popup, or the window (or the iframe the page is in) at once, closes it after closeDelay (50 ms).
  • Press: a press (or Enter, Space) on a Trigger toggles its Content, and focus stays on the Trigger. A pressed Content stays open when the pointer leaves; a press within 500 ms of a hover opening keeps it open. Touch opens and closes with a tap.
  • Keyboard: every Trigger and Link of the List is in the tab order; the arrow keys along the orientation move between them (mirrored in RTL), Home and End go to the ends. ArrowDown on a Trigger (ArrowRight in a vertical List) opens it with focus inside. From an open Trigger, Tab enters its Content; Tab from the Content's end continues after the Trigger.
  • Close: Escape (focus back on the Trigger when it was inside), a press outside, or focus leaving the navigation.
  • One popup: the open Content renders into the Viewport, inside the Popup. The Popup's --popup-width and --popup-height are the open Content's size: transition them, and lay the Contents out absolutely, so a switch moves from one size to the next while the old Content exits and the new one enters, each with data-activation-direction.
  • Nested levels: a Root inside a Content is a nested level (usually orientation="vertical"), with its own Portal; Escape and outside presses close one level at a time (nested overlays).

Anatomy

partelementdata-primitives-partrole
Rootnav (nested: div)navigation-menu-rootholds the open item; name it with aria-label
Listulnavigation-menu-listthe items
Itemlinavigation-menu-itema Trigger with its Content, or a Link
Triggerbuttonnavigation-menu-triggerdiscloses its item's Content
Iconspannavigation-menu-icona decorative chevron
Contentdivnavigation-menu-contentthe item's panel, rendered into the Viewport while open
Linkanavigation-menu-linka link, in the List or a Content
Portalnonemoves the Backdrop and the Positioner to the end of body while open
Backdropdivnavigation-menu-backdropcovers the page (optional)
Positionerdivnavigation-menu-positionerplaces the popup next to the open Trigger
Popupdivnavigation-menu-popupthe shared popup
Viewportdivnavigation-menu-viewportwhere the Contents render
Arrowdivnavigation-menu-arrowpoints at the Trigger (optional)

Usage

import { NavigationMenu } from "@fragiola/primitives-react/navigation-menu";

function SiteHeader() {
    return (
        <NavigationMenu.Root aria-label="Main">
            <NavigationMenu.List>
                <NavigationMenu.Item>
                    <NavigationMenu.Trigger>
                        Products
                        <NavigationMenu.Icon />
                    </NavigationMenu.Trigger>
                    <NavigationMenu.Content>
                        <NavigationMenu.Link href="/analytics">Analytics</NavigationMenu.Link>
                        <NavigationMenu.Link href="/reports">Reports</NavigationMenu.Link>
                    </NavigationMenu.Content>
                </NavigationMenu.Item>
                <NavigationMenu.Item>
                    <NavigationMenu.Link href="/pricing" active>Pricing</NavigationMenu.Link>
                </NavigationMenu.Item>
            </NavigationMenu.List>
            <NavigationMenu.Portal>
                <NavigationMenu.Positioner sideOffset={8}>
                    <NavigationMenu.Popup>
                        <NavigationMenu.Viewport />
                    </NavigationMenu.Popup>
                </NavigationMenu.Positioner>
            </NavigationMenu.Portal>
        </NavigationMenu.Root>
    );
}
[data-primitives-part="navigation-menu-popup"] {
    box-sizing: content-box;
    width: var(--popup-width);
    height: var(--popup-height);
    transition: width 200ms, height 200ms;
}
[data-primitives-part="navigation-menu-content"] { position: absolute; width: max-content; }

Props

Every part also takes what the primitive contract gives. The names below are React's; Vue binds them the same way (v-model:value, @value-change), and Angular as inputs and outputs ([(value)], (valueChangeDetails)).

Root

proptypedefaultdescription
valuestring | nullthe open item's value, controlled (null: closed)
defaultValuestring | nullnullthe open item, uncontrolled
onValueChange(value: string | null, details: ChangeDetails) => voidevery change, with its reason (trigger-hover, trigger-press, list-navigation, escape-key, outside-press, focus-out, none)
delaynumber50ms before a hover opens
closeDelaynumber50ms before the pointer leaving closes
orientation"horizontal" | "vertical""horizontal"the List's axis: its arrow keys and the Trigger's open key
loopFocusbooleantruethe arrow keys wrap at the ends

List

No props of its own.

Item

proptypedefaultdescription
valuestringgeneratedthe item's value

Trigger

proptypedefaultdescription
disabledbooleanfalsea disabled trigger opens nothing

Icon

No props of its own.

Content

No props of its own.

proptypedefaultdescription
activebooleanfalsethe link of the current page: aria-current="page" and data-active

Portal

proptypedefaultdescription
container (react, vue)Elementdocument.bodywhere the Backdrop and the Positioner go
options (angular)Element | { container? }{}the same option: *navigationMenuPortal="{ container: element }"

Backdrop

No props of its own.

Positioner

proptypedefaultdescription
sideSide"bottom"the side of the Trigger it sits on
alignAlign"center"its alignment along that side
sideOffsetnumber0the distance from the Trigger, in px
alignOffsetnumber0the shift along the side, in px
collisionPaddingnumber8the space kept from the viewport's edges when flipping and shifting
anchorElementthe open Triggeranother element to anchor to

No props of its own.

Viewport

No props of its own.

Arrow

No props of its own.

State and part attributes

partattributes
Root, Listdata-orientation
Triggeraria-expanded, aria-controls (its Content, while open), data-popup-open, data-disabled
Iconaria-hidden="true", data-popup-open
Contentan id, data-open / data-closed, data-starting-style, data-ending-style, data-activation-direction (left, right, up, down, none)
Linkaria-current="page" and data-active when active
Backdroparia-hidden="true", data-open / data-closed, data-starting-style, data-ending-style
Positionerrole="presentation", data-open / data-closed, data-side, data-align, the inline --positioner-width, --positioner-height and the anchor's variables
Popupdata-open / data-closed, data-side, data-align, data-starting-style, data-ending-style, the inline --popup-width, --popup-height
Arrowaria-hidden="true", data-open / data-closed, data-side, data-align

Keyboard

keyaction
Tab, Shift+Tabthrough the Triggers and Links; from an open Trigger into its Content, and from its end on after the Trigger
Enter, Space on a Triggertoggles its Content
ArrowDown on a Trigger (ArrowRight in a vertical List, ArrowLeft in RTL)opens its Content with focus inside
ArrowRight, ArrowLeft (ArrowDown, ArrowUp when vertical)the next or previous item, wrapping
Home, Endthe first, the last item
Escapecloses the open Content (one level at a time)

Exports

entryexports
@fragiola/primitives-react/navigation-menuNavigationMenu, NavigationMenuRootProps, NavigationMenuRootState, NavigationMenuOrientation, NavigationMenuItemProps, NavigationMenuTriggerProps, NavigationMenuTriggerState, NavigationMenuContentState, NavigationMenuLinkProps, NavigationMenuPortalProps, NavigationMenuPositionerProps, NavigationMenuPositionerState, NavigationMenuPopupState, PositionerProps, ActivationDirection, Side, Align, ChangeDetails, ChangeReason, RenderProp
@fragiola/primitives-vue/navigation-menuNavigationMenu, NavigationMenuRootProps, NavigationMenuRootEmits, NavigationMenuRootState, NavigationMenuOrientation, NavigationMenuListState, NavigationMenuItemProps, NavigationMenuTriggerProps, NavigationMenuTriggerState, NavigationMenuContentState, NavigationMenuLinkProps, NavigationMenuPortalProps, NavigationMenuPositionerState, NavigationMenuPopupState, PositionerProps, ActivationDirection, Side, Align, ChangeDetails, ChangeReason, RenderSlotProps
@fragiola/primitives-angular/navigation-menuNavigationMenuRoot, NavigationMenuList, NavigationMenuItem, NavigationMenuTrigger, NavigationMenuIcon, NavigationMenuContent, NavigationMenuLink, NavigationMenuPortal, NavigationMenuBackdrop, NavigationMenuPositioner, NavigationMenuPopup, NavigationMenuViewport, NavigationMenuArrow, NavigationMenuRootState, NavigationMenuOrientation, NavigationMenuTriggerState, NavigationMenuContentState, NavigationMenuPositionerState, NavigationMenuPopupState, OverlayPortalOptions, ValueChangeEvent, ActivationDirection, Side, Align, ChangeDetails, ChangeReason