Skip to main content

menu

The menu component creates context menus and dropdown menus.

Usage

Modular:

import { menu } from "/42/ui/layout/menu.js"

const myMenu = await menu({
items: [
{ text: "Open", picto: "folder-open", action: () => {} },
{ text: "Save", picto: "save", action: () => {} },
"-",
{ text: "Delete", picto: "trash", action: () => {} },
],
})

Plan:

{
tag: "ui-menu",
items: [
{ text: "Open", picto: "folder-open", action: () => {} },
{ text: "Save", picto: "save", action: () => {} },
"-",
{ text: "Delete", picto: "trash", action: () => {} },
],
}

Basic menu

const result = await menu({
items: [
{ text: "Open", picto: "folder-open", action: () => {} },
{ text: "Save", picto: "save", action: () => {} },
"-",
{ text: "Delete", picto: "trash", action: () => {} },
],
})
PropertyTypeDescription
textStringLabel text
pictoStringIcon identifier
actionFunctionCalled when item is clicked
disabledBooleanWhether item is greyed out
separatorBooleanRenders a divider line
childrenArraySubmenu items

Positioning

Menus automatically position themselves near the cursor or triggering element. Use position to override:

menu({ items: [...], position: { my: "left top", at: "left bottom" } })

Events

  • ui:menu.open - fired when menu opens
  • ui:menu.close - fired when menu closes