MenuItem

free

MenuItem aligns custom navigation and action rows to the Menu interaction model.

Preview
Dark
import { useState } from 'react';
import { PiBell, PiCreditCard, PiUser } from 'react-icons/pi'
import { MenuItem } from '@/components/ui';

const items = [
  { key: 'profile', label: 'Profile', icon: PiUser },
  { key: 'billing', label: 'Billing', icon: PiCreditCard },
  { key: 'notifications', label: 'Notifications', icon: PiBell },
];

export default function UsageDemo() {
  const [activeKey, setActiveKey] = useState('profile');

  return (
    <div className="w-full max-w-[250px] space-y-1">
      {items.map((item) => {
        const Icon = item.icon;

        return (
          <MenuItem
            key={item.key}
            eventKey={item.key}
            isActive={activeKey === item.key}
            onSelect={(key: string) => setActiveKey(key)}
          >
            <Icon className="text-base text-muted-foreground" />
            {item.label}
          </MenuItem>
        );
      })}
    </div>
  );
}

Installation

Add this component with the NateUI CLI.

npx nateui@latest add MenuItem

Examples

Basic

Preview
Dark
import { MenuItem } from '@/components/ui';

export default function BasicDemo() {
  return (
    <div className="w-full max-w-[250px] space-y-1">
      <MenuItem eventKey="overview">Overview</MenuItem>
      <MenuItem eventKey="customers">Customers</MenuItem>
      <MenuItem eventKey="orders">Orders</MenuItem>
    </div>
  );
}

States

Preview
Dark
import { MenuItem } from '@/components/ui';

export default function StatesDemo() {
  return (
    <div className="w-full max-w-[250px] space-y-1">
      <MenuItem eventKey="available">Available</MenuItem>
      <MenuItem eventKey="selected" isActive>
        Selected
      </MenuItem>
      <MenuItem eventKey="disabled" disabled>
        Disabled
      </MenuItem>
    </div>
  );
}

Rendered Element

Preview
Dark
Menu docs
import { PiArrowRight } from 'react-icons/pi'
import { MenuItem } from '@/components/ui';

export default function RenderedElementDemo() {
  return (
    <div className="w-full max-w-[250px] space-y-1">
      <MenuItem asElement="a" href="/components/ui/menu" eventKey="menu">
        Menu docs
        <PiArrowRight className="ms-auto text-base text-muted-foreground" />
      </MenuItem>
      <MenuItem asElement="button" type="button" eventKey="button">
        Button row
      </MenuItem>
    </div>
  );
}

Hierarchy Indicator

Preview
Dark
import { MenuItem } from '@/components/ui';

export default function HierarchyIndicatorDemo() {
  return (
    <div className="w-full max-w-[250px] space-y-1">
      <MenuItem eventKey="inbox" hierarchyIndicator>
        Inbox
      </MenuItem>
      <MenuItem eventKey="priority" hierarchyIndicator isActive>
        Priority
      </MenuItem>
      <MenuItem eventKey="archive" hierarchyIndicator>
        Archive
      </MenuItem>
    </div>
  );
}

API

MenuItem is the exported base item row used by Menu and Dropdown internals. It renders a configurable element, applies active/disabled data states, and can show a hierarchy indicator.

PropDescriptionTypeDefault
asElementElement or component rendered as the item root.ElementType'div'
childrenItem label or custom inline content.ReactNode-
classNameClass names merged with the base item and state classes.string-
disabledApplies disabled styling and data-disabled. Guard handlers separately when the item should be inert.boolean-
eventKeySelection key passed to onSelect.string-
hierarchyIndicatorShows the hierarchy indicator line before the item content.boolean-
idNative id applied to the rendered element.string-
indicatorClassNameClass names applied to the hierarchy indicator wrapper.string-
indicatorLineClassNameClass names applied to the hierarchy indicator line.string-
isActiveApplies active styling and data-state="active".boolean-
menuItemHeightItem height. Numbers are written as pixel values.string | number36
onSelectCalled with eventKey when the item is clicked.MenuItemSelectHandler-
refRef forwarded to the rendered item element.Ref<HTMLElement>-
...nativePropsNative props for the rendered root element.NativeMenuItemProps-

Types

type MenuItemSelectHandler = (eventKey: string, e: MouseEvent) => void;
type NativeMenuItemProps = ComponentProps<ElementType>;