Menu

free

Menu gives sidebar and nested navigation a clear active route context.

import { type ReactNode } from 'react';
import { PiBell, PiCreditCard, PiGear, PiUser, PiUsers } from 'react-icons/pi'
import Menu from '@/components/ui/menu';

Installation

Add this component with the NateUI CLI.

npx nateui@latest add Menu

Examples

Basic

import Menu from '@/components/ui/menu';

export default function BasicDemo() {
  return (

With Icons

import { type ReactNode } from 'react';
import { PiArchive, PiEnvelope, PiGear } from 'react-icons/pi'
import Menu from '@/components/ui/menu';

Collapsible

import { type ReactNode } from 'react';
import {
    PiArchive,
    PiEnvelope,

Groups

import Menu from '@/components/ui/menu';

export default function GroupsDemo() {
  return (

Active And Expanded

import Menu from '@/components/ui/menu';

export default function ActiveExpandedDemo() {
  return (

Disabled

import Menu from '@/components/ui/menu';

export default function DisabledDemo() {
  return (

API

Menu is a compound component: Menu provides shared active, expanded, and selection context; Menu.MenuItem, Menu.MenuCollapse, and Menu.MenuGroup render the list structure.

PropDescriptionTypeDefault
childrenMenu item, group, or collapse content rendered inside the root list.ReactNode-
classNameClass names applied to the root ul.string-
collapsedSwitches menu context into collapsed mode for group labels and collapse indicators.booleanfalse
defaultActiveKeysKeys matched against descendant menu items to mark them active.string[][]
defaultCollapseActiveKeysKeys matched against collapse rows to mark those rows active.string[][]
defaultExpandedKeysCollapse keys opened when the menu renders or when the key list changes.string[][]
onSelectCalled when a menu item selects an eventKey.MenuSelectHandler-
refRef forwarded to the root ul.Ref<HTMLUListElement>-
...nativePropsNative props applied to the root ul.NativeMenuProps-
PropDescriptionTypeDefault
asElementElement or component rendered for the item.ElementType'li'
childrenItem label or custom content.ReactNode-
classNameClass names merged with the item state classes.string-
disabledApplies disabled styling and data-disabled to the item.boolean-
eventKeySelection key passed to onSelect and matched by active key props.string-
hierarchyIndicatorShows the hierarchy indicator line before the item content.boolean-
indicatorClassNameClass names applied to the hierarchy indicator wrapper.string-
indicatorLineClassNameClass names applied to the hierarchy indicator line.string-
isActiveForces the item into the active state independent of defaultActiveKeys.boolean-
onSelectItem-level select handler. Falls back to Menu context onSelect.MenuSelectHandlerMenu onSelect
refRef forwarded to the rendered item element.Ref<HTMLElement>-
variantVisual treatment for active and hover states.MenuVariant'default'
...nativePropsNative props applied to the rendered item element.NativeMenuItemProps-
PropDescriptionTypeDefault
activeMarks the collapse trigger row active.boolean-
childrenNested menu items, groups, or collapse rows.ReactNode-
classNameClass names applied to the collapse trigger row.string-
eventKeyKey matched by defaultExpandedKeys and defaultCollapseActiveKeys.string-
expandedOpens the collapse row by default.booleanfalse
hierarchyIndicatorShows the hierarchy indicator before the trigger label.boolean-
indentIndents the nested content list.booleantrue
labelTrigger row label.string | ReactNodenull
onToggleCalled when the trigger row changes expanded state.MenuToggleHandler-
...nativePropsNative props applied to the root li.NativeMenuCollapseProps-
PropDescriptionTypeDefault
childrenMenu items or collapse rows rendered inside the group list.ReactNode-
classNameClass names applied to the group wrapper.string-
labelGroup heading content. Required.string | ReactNode-
...nativePropsNative props applied to the group wrapper.NativeMenuGroupProps-

Types

type MenuVariant = 'default' | 'subtle';
 
type MenuSelectHandler = (eventKey: string, e: MouseEvent) => void;
 
type MenuToggleHandler = (
  expanded: boolean,
  e: MouseEvent<HTMLDivElement>,
) => void;
 
type NativeMenuProps = ComponentProps<'ul'>;
type NativeMenuItemProps = ComponentProps<ElementType>;
type NativeMenuCollapseProps = ComponentProps<'li'>;
type NativeMenuGroupProps = ComponentProps<'div'>;