• CMSnpm version

    • Overview
    • ContentBuilder
    • InviteUserForm
    • LoginForm
    • RenewPasswordForm
  • UInpm version

    • Overview
    • Accordion
    • AlertBubble
    • AnnouncementBar
    • Avatar
    • AvatarFileInput
    • Badge
    • Button
    • ButtonGroup
    • ButtonList
    • Calendar
    • Checkbox
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • Chip
    • ColorRadio
    • ColorRadioGroup
    • Combobox
    • DatePicker
    • DatePickerInput
    • DateRangePicker
    • DateRangePickerInput
    • DatetimePicker
    • DatetimePickerInput
    • Dialog
    • Dropdown
    • Dropzone
    • ErrorMessage
    • FileInput
    • FlashMessages
    • FormComponent
    • Icon
    • IconButton
    • ImageGallery
    • InfoBox
    • Input
    • Label
    • Layout
    • Lightbox
    • ListItem
    • Loader
    • Lozenge
    • Menu
    • Message
    • Modal
    • ✅ ModalDialog
    • ✅ ModalHeader
    • MultiCombobox
    • MultiSelect
    • Pagination
    • Paper
    • Popover
    • Radio
    • RadioGroup
    • RasterImage
    • Select
    • ✅ Tabs
    • TextInput
    • TextLink
    • Textarea
    • TimePicker
    • TimePickerInput
    • Toggle
    • Tooltip
    • Typography
  • Formnpm version

    • Overview
    • AvatarFileInput
    • CheckboxButton
    • CheckboxInput
    • CheckboxList
    • ColorRadioGroup
    • Combobox
    • DatePickerInput
    • DateRangePickerInput
    • DatetimePickerInput
    • Dropzone
    • FileInput
    • Form
    • FormRenderer
    • GpsInput
    • MoneyInput
    • MultiCombobox
    • MultiSelect
    • NumberInput
    • PasswordInput
    • RadioGroup
    • Select
    • TextInput
    • Textarea
    • TimePickerInput
    • Toggle
  • DataGridnpm version

    • Overview
    • DataGrid
    • DataGridCustomExample
    • ExportButton
    • FilterList
    • Filters
    • FiltersButton
    • FulltextInput
    • HiddenColumns
    • HiddenColumnsButton
    • Pagination
    • RowCounts
    • RowsPerPageSelect
    • SelectedRowsToolbar
    • TableV2
    • ToolbarControl
    • ToolbarCustoms
    • ToolbarTabs
  • Wysiwygnpm version

    • Overview
  • Resizernpm version

    • Overview
  • Routernpm version

    • Overview
  • Corenpm version

    • Overview
  • Core-Reactnpm version

    • Overview
  • Stylesnpm version

    • Overview
  • Localizenpm version

    • Overview
  • Analyticsnpm version

    • Overview
  • Datepickernpm version

    • Overview
  • Icons-generatornpm version

    • Overview
  • Smart-addressnpm version

    • Overview
  • E2Enpm version

    • Overview
  • E2E-Playwrightnpm version

    • Overview
View source on GitLab

Menu

A configuration-driven vertical navigation menu (sidebar). It renders a tree of links/buttons from a configuration array, resolves the active branch from the current route, and supports a collapsed (icons-only) mode and popover submenus.

When to use

Use Menu for app navigation where items are known up front and active state follows the route. For a contextual action menu opened from a trigger, use Dropdown with a headless layer, or Popover for a custom floating panel.

Collapsed and popover submenus are rendered with the internal Popover component.

There is no @uxf/form twin.

Usage

import { Menu } from "@uxf/ui/menu";

<Menu
    configuration={[
        { label: "Home", icon: "eye", href: "/", routeMatcher: (pathname) => pathname === "/" },
        {
            label: "Reports",
            icon: "file",
            children: [{ label: "Monthly", href: "/reports/monthly", icon: "copy" }],
        },
        { label: "Sign out", icon: "file", onClick: () => signOut() },
    ]}
    router={{ pathname: "/", pathParams: {} }}
/>;

MenuConfiguration / MenuItemConfiguration are not re-exported from the package index; type an inline array against MenuProps["configuration"], or deep-import from @uxf/ui/menu/menu / @uxf/ui/menu/types.

Wiring the active item

Pass the current route into router. Menu calls each item's routeMatcher(pathname, pathParams) and marks an item active when it matches (a parent is active when any descendant is).

// app directory
import { usePathname } from "next/navigation";
import { usePageParams } from "@app-routes";

const pathname = usePathname();
const pathParams = usePageParams();

<Menu configuration={configuration} router={{ pathname, pathParams }} />;
// pages directory
import { useRouter } from "next/router";

const router = useRouter();

<Menu configuration={configuration} router={router} />;

Props

PropTypeDefaultDescription
configurationMenuItemConfiguration[]—Required. Menu tree (see item shape below).
router{ pathname: string | null; pathParams?: RouterPathParams | null }—Required. Current route, used to resolve the active item.
isCollapsedbooleanfalseCollapse to icons only; labels and right elements are hidden and submenus open in a hover popover.
isPopoverEnabledbooleanfalseRender submenus in a hover popover instead of expanding inline.
classNamestring—Extra class on the root uxf-menu element.

MenuItemConfiguration

FieldTypeDescription
labelstringRequired. Item text (also used as title).
iconIconNameLeading icon.
hrefstringRenders the item as a link.
as"a" | NextLinkLink component used when href is set (defaults to <a>).
onClick() => voidRenders the item as a <button>; on an item with children, clicking toggles expansion when no onClick is given.
childrenMenuItemConfiguration[]Submenu items.
routeMatcher(pathname: string, pathParams?: RouterPathParams) => booleanReturns true when the item is active for the current route.
badgeReactElementElement rendered on the right (a dot indicator when collapsed).

Variants & states

  • Item rendering: an item with href renders a link (as/NextLink or <a>); with onClick and no children it renders a <button>; with children it toggles a submenu; with none of these it renders a non-interactive <div>.
  • Active branch: items whose routeMatcher matches are marked active, and ancestors of an active item are active too. Branches start expanded when active (unless collapsed).
  • Collapsed / popover submenus: in isCollapsed or isPopoverEnabled mode, submenus appear in a right-start hover popover.

Requirements

Import the component stylesheet once in your global CSS:

@import url("@uxf/ui/css/menu.css");

Also requires the global @uxf/ui token layer, set up once per app — see @uxf/ui setup.

Default
Open in new tab