PeakUI

Menu

Inline menu that is always visible

Usage

import {Menu} from "@peakui/react";

Anatomy

import {Label, Menu, Separator} from "@peakui/react";

// Menu.Item, Menu.Section and the indicators are the menu parts shared with Dropdown.
// Dividers use Separator; there is no Menu.Separator.
export default () => (
  <Menu aria-label="Actions">
    <Menu.Item>
      <Label />
      <Menu.ItemIndicator />
    </Menu.Item>
    <Separator />
    <Menu.Section aria-label="Section">
      <Menu.Item>
        <Label />
        <Menu.SubmenuIndicator />
      </Menu.Item>
    </Menu.Section>
  </Menu>
);

Examples

With Sections

With Selection

Customization

Tailwind CSS

<Menu aria-label="Actions" className="w-60 rounded-xl border border-border p-2">
  <Menu.Item id="new" textValue="New file">
    <Label>New file</Label>
  </Menu.Item>
</Menu>

Global CSS

@layer components {
  .menu {
    @apply gap-1 rounded-xl border border-border p-2;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Menu component uses these CSS classes (view source styles):

Base Classes

  • .menu - Inline menu container
  • .menu-item - Menu item
  • .menu-section - Menu section

Element Classes

  • .menu-item__indicator - Selection indicator of an item
  • .menu-item__indicator--submenu - Submenu indicator of an item

Variant Classes

  • .menu-item--default
  • .menu-item--danger

Slots

  • [data-slot="menu"]
  • [data-slot="menu-item"]
  • [data-slot="menu-section"]
  • [data-slot="menu-item-indicator"]
  • [data-slot="menu-item-indicator--checkmark"]
  • [data-slot="menu-item-indicator--dot"]
  • [data-slot="submenu-indicator"]

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Selection mode: [data-selection-mode] on the menu
  • Hover: :hover or [data-hovered="true"] on an item
  • Focus: :focus-visible or [data-focus-visible="true"] on an item
  • Pressed: :active or [data-pressed="true"] on an item
  • Selected: [aria-checked="true"], [aria-selected="true"] or [data-selected="true"] on an item; [data-visible] on its indicator
  • Disabled: [data-disabled="true"] on an item
  • Submenu: [data-has-submenu="true"] on an item

API Reference

PropTypeDefaultDescription
selectionMode"single" | "multiple" | "none""none"Whether single or multiple selection is enabled
selectedKeysIterable<Key>-The currently selected keys (controlled)
defaultSelectedKeysIterable<Key>-The initial selected keys (uncontrolled)
onSelectionChange(keys: Selection) => void-Handler called when the selection changes
disabledKeysIterable<Key>-Keys of disabled items
onAction(key: Key) => void-Handler called when an item is activated
classNamestring | ((values) => string)-Additional CSS classes
childrenReactNode-Menu content
...restMenuProps<T>-React Aria Menu attributes
PropTypeDefaultDescription
idKey-Unique identifier for the item
textValuestring-Text content of the item for typeahead
variant"default" | "danger""default"Visual variant of the item
isDisabledboolean-Whether the item is disabled
hrefstring-Renders the item as a link to this URL
classNamestring-Additional CSS classes
childrenReactNode | RenderFunction-Item content or render function
...restMenuItemProps-React Aria MenuItem attributes
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode-Section content
...restMenuSectionProps-React Aria MenuSection attributes
PropTypeDefaultDescription
type"checkmark" | "dot""checkmark"Type of indicator to display
classNamestring-Additional CSS classes
childrenReactNode | RenderFunction-Custom indicator content or render function
PropTypeDefaultDescription
classNamestring-Additional CSS classes
childrenReactNode-Custom indicator content

On this page