Application and context menus.
Requires the 'menu' permission in volt.config.ts.
Build a menu from an array of item options.
import { Menu } from 'voltkit';
const menu = Menu.buildFromTemplate([
{
label: 'File',
type: 'submenu',
submenu: [
{ label: 'New', accelerator: 'CmdOrCtrl+N' },
{ type: 'separator' },
{ label: 'Quit', role: 'quit' },
],
},
{
label: 'Edit',
type: 'submenu',
submenu: [
{ label: 'Copy', role: 'copy' },
{ label: 'Paste', role: 'paste' },
],
},
]);Set the application menu bar. Pass null to clear.
Menu.setApplicationMenu(menu);Get the current application menu.
Add a menu item.
Get all items (returns a copy).
Serialize the menu to a template for native code.
import { MenuItem } from 'voltkit';
const item = new MenuItem({
label: 'Save',
accelerator: 'CmdOrCtrl+S',
click: () => { /* handle click */ },
});| Field | Type | Default | Description |
|---|---|---|---|
label |
string |
'' |
Display label |
accelerator |
string |
— | Keyboard shortcut (e.g., 'CmdOrCtrl+C') |
enabled |
boolean |
true |
Whether the item is interactive |
type |
'normal' | 'separator' | 'submenu' |
'normal' |
Item type |
role |
MenuItemRole |
— | Predefined system action |
click |
() => void |
— | Click handler |
submenu |
MenuItemOptions[] |
— | Nested items (for type: 'submenu') |
Predefined roles that auto-configure label and accelerator:
'quit' | 'copy' | 'cut' | 'paste' | 'selectAll' | 'undo' | 'redo' | 'minimize' | 'separator'