Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Overlays

Menu

Dropdown list of actions. Arrow keys, Home/End, typing a letter and Esc all work.

import { Menu } from "@stylhero/ui";

Example

Code
import { Button, Menu } from "@stylhero/ui";

function MenuExample() {
  return (
    <Menu trigger={<Button variant="secondary">Actions</Button>} items={[
      { label: "Rename", onSelect: () => {} },
      { label: "Duplicate", shortcut: "Ctrl+D", onSelect: () => {} },
      { label: "Open on GitHub", href: "https://github.com/raiburn/stylhero" },
      "separator",
      { label: "Delete", danger: true, onSelect: () => {} },
    ]} />
  );
}

Props

PropTypeDefaultDescription
items required MenuItem[] -
trigger required ReactElement - The element that opens the menu, e.g. <IconButton label="More"><MoreHorizontal /></IconButton>.
className string -
placement Placement "bottom-start"

Types

type MenuItem = MenuAction | "separator";

type MenuAction = {
  label: string;
  icon?: ReactNode;
  onSelect?: () => void;
  /** Renders a link instead of a button. */
  href?: string;
  /** Red, for destructive actions. Put them last. */
  danger?: boolean;
  disabled?: boolean;
  /** Keyboard hint on the right, e.g. "Ctrl+D". */
  shortcut?: string;
};

Keyboard

KeyDoes
Enter / Space / ArrowDownOpen the menu from the trigger
ArrowDown / ArrowUpMove through the items
Typing a letterJumps to the next item that starts with it
EnterActivates the item
EscCloses it and returns focus to the trigger

Accessibility

  • Follows the ARIA menu pattern (role="menu" and menuitem), with focus kept on the active item.

Generated from src/components/Menu.tsx. Something wrong or missing? Open an issue.