Menu
A dropdown menu (menu button pattern: arrows, Home/End, typeahead, Enter, Escape) or, with context, a context menu at the pointer.
release-notes.md12 KB · 2 h ago screenshot-dark.png1.8 MB · yesterday bundles6 files · Oct 2
In a raylang app
With native and the native bridge, the menu opens as the system's context menu at the pointer: its items and dividers, disabled ones greyed out. The choice fires the same ray-select, so the same code handles both.
<ray-menu native context>
<div slot="trigger" class="file-row">report.csv</div>
<ray-menu-item value="open">Open</ray-menu-item>
<ray-menu-item value="reveal">Show in Finder</ray-menu-item>
<ray-menu-divider></ray-menu-divider>
<ray-menu-item value="delete" color="red">Delete</ray-menu-item>
</ray-menu>
Checkbox and radio items show their check mark there too. Labels, nested menus, icons and colors are the page menu's only. A dismissed native menu fires nothing.
The native menu reads its items the moment it opens, so items that depend on what was clicked go in ray-request-open, which comes first (a contextmenu listener of your own on the trigger may run after the menu's):
menu.addEventListener("ray-request-open", (e) => {
const row = e.detail.event.target.closest(".file-row");
menu.replaceChildren(menu.querySelector("[slot=trigger]"), ...itemsFor(row));
});API
For AI agents: this API as Markdown, or every component in llms-full.txt.
<ray-menu>
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
open | open reflects | boolean | Shown. | |
placement | placement reflects | bottom-start | bottom | bottom-end | top-start | top | top-end | right-start | left-start | bottom-start | Preferred side and alignment: top/bottom/left/right are sides of the screen; on top and bottom, -start/-end follow the writing direction (right to left, "bottom-start" lines up the right edges). |
context | context reflects | boolean | Opens on right click (contextmenu) over the trigger area, at the pointer. | |
keepOpen | keep-open reflects | boolean | Choosing an item does not close the menu. | |
native | native reflects | boolean | With a native host (ray-elements/core/raylang.js in a std/ui window), opens as the system's context menu at the pointer: items and dividers, same ray-select. Where the system has none (a phone: the bridge does not offer it) or the call fails, the page's menu opens. | |
anchor | — | object | What the panel is placed against instead of the trigger: an element, a DOMRect or a function returning one (a text range, the pointer; read again on every reposition). The trigger still opens it. |
| Event | Description |
|---|---|
ray-select | An item was chosen; detail: { value, item }. |
ray-request-open | Its trigger is about to open it (click, Arrow keys, right click), before the items are read, native menu included: fill items that depend on what was clicked here. Cancelable (preventDefault keeps it closed). Not fired by show() or open = true. detail: { event }. |
ray-open | After it opened. |
ray-close | After it closed. |
| Slot | Description |
|---|---|
trigger | The button that opens it, or the area for a context menu (a press on the area outside the open menu closes it; a right click reopens it at the new point). |
| (default) | ray-menu-item, ray-menu-label and ray-menu-divider elements. |
| Part | Description |
|---|---|
dropdown | The panel. |
<ray-menu-item>
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
value | value reflects | string | Reported in ray-select (default: the text). | |
disabled | disabled reflects | boolean | Skipped by the keyboard, cannot be chosen. | |
color | color reflects | string | Text and hover color (e.g. red for destructive actions). | |
type | type reflects | item | checkbox | radio | item | checkbox: choosing it toggles checked (menuitemcheckbox); radio: choosing it checks it and unchecks the radio items of the menu with the same name (menuitemradio). Both show a check mark when checked, in the native menu too. |
checked | checked reflects | boolean | Checked (checkbox and radio items). Already updated when ray-select fires. | |
name | name reflects | string | The group of a radio item: one checked per name in the menu. |
| Slot | Description |
|---|---|
| (default) | Label. |
left | Icon. |
right | Shortcut or badge. |
| Part | Description |
|---|---|
mark | The check mark of a checkbox or radio item. |
<ray-menu-label>
A section caption inside the menu.
<ray-menu-divider>
A separator between groups of items.