ray-menuray-menu

Getting Started

Get up and running with Ray Menu in minutes

Getting Started

This guide will help you add Ray Menu to your project and create your first radial menu.

Installation

npm install ray-menu

Basic Usage

<script type="module">
  import "ray-menu";
</script>

<ray-menu id="menu"></ray-menu>

<script>
  const menu = document.getElementById("menu");
  menu.items = [
    { id: "copy", label: "Copy", shortcut: "⌘C" },
    { id: "paste", label: "Paste", shortcut: "⌘V" },
    { id: "cut", label: "Cut", shortcut: "⌘X" },
    { id: "delete", label: "Delete", shortcut: "⌫" },
  ];

  // Open on right-click
  document.addEventListener("contextmenu", (e) => {
    e.preventDefault();
    menu.open(e.clientX, e.clientY);
  });

  // Handle selection
  menu.addEventListener("ray-select", (e) => {
    console.log("Selected:", e.detail.label);
  });
</script>

Nested Submenus

Items with children automatically create submenus:

menu.items = [
  { id: "copy", label: "Copy" },
  {
    id: "share",
    label: "Share",
    selectable: false,
    children: [
      { id: "email", label: "Email" },
      { id: "link", label: "Copy Link" },
      { id: "social", label: "Social" },
    ],
  },
];

Async Submenus

Load submenu items dynamically with loadChildren:

menu.items = [
  {
    id: "move",
    label: "Move to",
    selectable: false,
    loadChildren: async () => {
      const folders = await fetchFolders();
      return folders.map((f) => ({ id: f.id, label: f.name }));
    },
  },
];

How It Works

Ray Menu uses a radial selection model:

  1. Trigger - Right-click or programmatically call menu.open(x, y)
  2. Navigate - Move your cursor in the direction of the item
  3. Select - Click or release to select the highlighted item

The menu uses infinite radial selection - items are selected based on angle from center, not distance.

Next Steps

On this page