Skip to content
Ginga UI
Ginga UI
日本語

Getting started

  • Overview
  • Quick start
  • Theme generation
  • Custom rendering
  • All components

Forms

  • Button
  • Checkbox
  • Input
  • Radio
  • Questionnaire
  • SegmentedControl
  • Select
  • ComboBox
  • NumberField
  • SearchField
  • Slider
  • Switch
  • FormControl

Display

  • Accordion
  • Alert
  • AlertDialog
  • Badge
  • CodeBlock
  • Card
  • Dialog
  • Drawer
  • Image
  • List
  • Popover
  • Menu
  • Tooltip
  • Table
  • Tab
  • Toast
  • Trace

Typography

  • Heading
  • Paragraph

Navigation

  • Anchor

Layout

  • Box

Resources

  • Changelog
  • GitHub (opens in a new tab)

Logo: Twemoji (opens in a new tab) (CC-BY 4.0)

Menu

A dropdown list of actions opened from a button. Supports sections, submenus, and selection.

View in Storybook (opens in a new tab)

Installation

import { Menu } from "@ginga-ui/core";

Basic usage

Put a Button and a Menu inside MenuTrigger. Use onAction to handle the chosen item.

menu.tsx
import { Button, Menu, MenuItem, MenuSeparator, MenuTrigger } from "@ginga-ui/core";
import { Copy, Pencil, Trash2 } from "lucide-react";

export function BasicExample() {
  return (
    <MenuTrigger>
      <Button variant="outline">Actions</Button>
      <Menu onAction={(key) => console.log("Action:", key)}>
        <MenuItem id="edit" startIcon={<Pencil />} shortcut="⌘E">
          Edit
        </MenuItem>
        <MenuItem id="duplicate" startIcon={<Copy />} shortcut="⌘D">
          Duplicate
        </MenuItem>
        <MenuSeparator />
        <MenuItem id="delete" startIcon={<Trash2 />}>
          Delete
        </MenuItem>
      </Menu>
    </MenuTrigger>
  );
}

Sections

Group items with MenuSection and separate them with MenuSeparator.

menu.tsx
import { Button, Menu, MenuItem, MenuSection, MenuSeparator, MenuTrigger } from "@ginga-ui/core";

export function SectionExample() {
  return (
    <MenuTrigger>
      <Button variant="outline">File</Button>
      <Menu>
        <MenuSection title="Create">
          <MenuItem id="new">New</MenuItem>
          <MenuItem id="open">Open</MenuItem>
        </MenuSection>
        <MenuSeparator />
        <MenuSection title="Export">
          <MenuItem id="pdf">PDF</MenuItem>
          <MenuItem id="png" disabled>
            PNG
          </MenuItem>
        </MenuSection>
      </Menu>
    </MenuTrigger>
  );
}

Submenu

Put a MenuItem and a nested Menu inside SubmenuTrigger.

menu.tsx
import { Button, Menu, MenuItem, MenuTrigger, SubmenuTrigger } from "@ginga-ui/core";
import { ChevronRight, Copy } from "lucide-react";

export function SubmenuExample() {
  return (
    <MenuTrigger>
      <Button variant="outline">Share</Button>
      <Menu submenuIcon={<ChevronRight />}>
        <MenuItem id="copy-link">Copy link</MenuItem>
        <SubmenuTrigger>
          <MenuItem id="send">Send to</MenuItem>
          <Menu>
            <MenuItem id="mail">Email</MenuItem>
            <MenuItem id="chat">Chat</MenuItem>
          </Menu>
        </SubmenuTrigger>
      </Menu>
    </MenuTrigger>
  );
}

Selection

Set selectionMode to show a check next to the selected items.

menu.tsx
import { useState } from "react";
import { Button, Menu, MenuItem, MenuTrigger } from "@ginga-ui/core";
import { Check } from "lucide-react";
import type { Selection } from "react-aria-components";

export function SelectionExample() {
  const [selected, setSelected] = useState<Selection>(new Set(["grid"]));
  return (
    <MenuTrigger>
      <Button variant="outline">View</Button>
      <Menu
        checkIcon={<Check />}
        selectionMode="single"
        selectedKeys={selected}
        onSelectionChange={setSelected}
      >
        <MenuItem id="list">List</MenuItem>
        <MenuItem id="grid">Grid</MenuItem>
        <MenuItem id="board">Board</MenuItem>
      </Menu>
    </MenuTrigger>
  );
}

Props

MenuTrigger

Accepts the props of React Aria's MenuTrigger (opens in a new tab).

Menu

NameTypeDefaultDescription
childrenReactNode-MenuItem, MenuSection, MenuSeparator, and SubmenuTrigger elements.
placementPlacement"bottom start"Position of the menu relative to the trigger.
offsetnumber-Distance from the trigger in pixels.
checkIconReactNode-Icon shown next to selected items. A check mark is drawn when omitted. Inherited by submenus.
submenuIconReactNode-Icon shown at the end of items that open a submenu. A chevron is drawn when omitted. Inherited by submenus.

Also accepts the props of React Aria's Menu (opens in a new tab).

MenuItem

NameTypeDefaultDescription
disabledbooleanfalseDisables the item.
startIconReactNode-Icon shown before the label.
shortcutstring-Keyboard shortcut shown at the end of the item. It is only displayed, not registered.
textValuestringchildren (string only)Text used for type-to-select and screen readers. Required when children is not a string.

Also accepts the props of React Aria's MenuItem (opens in a new tab).

MenuSection

NameTypeDefaultDescription
titleReactNode-Heading shown at the top of the section.

Also accepts the props of React Aria's MenuSection (opens in a new tab).

MenuSeparator

Accepts the props of React Aria's Separator (opens in a new tab).

SubmenuTrigger

Accepts the props of React Aria's SubmenuTrigger (opens in a new tab).