Skip to main content
The Menu API allows you to create native application menus with various menu item types including labels, links, checkboxes, radio buttons, and separators.

Creating a Menu

use Native\Desktop\Facades\Menu;
use Native\Desktop\Menu\Items\Label;
use Native\Desktop\Menu\Items\Link;
use Native\Desktop\Menu\Items\Separator;

$menu = Menu::make(
    Label::make('File'),
    Link::make('/settings', 'Settings')->accelerator('CmdOrCtrl+,'),
    Separator::make(),
    Label::make('Quit')->accelerator('CmdOrCtrl+Q')
);

$menu->register();

label

Set the label for the menu.
label
string
required
The label text for the menu
$menu->label('File');

add

Add a menu item to the menu.
item
MenuItem
required
A menu item instance (Label, Link, Checkbox, Radio, or Separator)
return
self
Returns the Menu instance for method chaining
use Native\Desktop\Menu\Items\Label;

$menu->add(Label::make('Settings'));

register

Register the menu with the application.
$menu->register();

Label

A standard clickable menu item.
use Native\Desktop\Menu\Items\Label;

$item = Label::make('Settings', 'CmdOrCtrl+,');
label
string
required
The text label for the menu item
accelerator
string
Optional keyboard shortcut (e.g., “CmdOrCtrl+Q”)
A menu item that navigates to a URL.
use Native\Desktop\Menu\Items\Link;

$item = Link::make('/dashboard', 'Dashboard')
    ->openInBrowser(false);
url
string
required
The URL to navigate to
label
string
required
The text label for the menu item
accelerator
string
Optional keyboard shortcut

openInBrowser

Set whether the link should open in the system browser.
openInBrowser
bool
default:"false"
Whether to open in browser
$item->openInBrowser(true);

Checkbox

A menu item with a checkbox.
use Native\Desktop\Menu\Items\Checkbox;

$item = Checkbox::make('Enable notifications', true);
label
string
required
The text label for the menu item
checked
bool
default:"false"
Whether the checkbox is initially checked
accelerator
string
Optional keyboard shortcut

Radio

A menu item with a radio button.
use Native\Desktop\Menu\Items\Radio;

$item = Radio::make('Dark mode', true);
label
string
required
The text label for the menu item
checked
bool
default:"false"
Whether the radio button is initially selected
accelerator
string
Optional keyboard shortcut

Separator

A visual separator between menu items.
use Native\Desktop\Menu\Items\Separator;

$item = Separator::make();

Common Menu Item Methods

All menu item types support the following methods:

id

Set a unique identifier for the menu item.
id
string
required
The unique identifier
$item->id('settings-item');

label

Set the label text.
label
string
required
The label text
$item->label('Settings');

sublabel

Set a secondary label text.
sublabel
string
required
The sublabel text
$item->sublabel('Configure application');

icon

Set an icon for the menu item.
icon
string
required
Path to the icon file
$item->icon('/path/to/icon.png');

accelerator

Set a keyboard shortcut.
accelerator
string
required
Keyboard shortcut (e.g., “CmdOrCtrl+Q”)
$item->accelerator('CmdOrCtrl+,');

hotkey

Alias for accelerator().
hotkey
string
required
Keyboard shortcut (e.g., “CmdOrCtrl+Q”)
$item->hotkey('CmdOrCtrl+,');

tooltip

Set a tooltip for the menu item.
tooltip
string
required
The tooltip text
$item->tooltip('Open settings');

enabled

Enable the menu item.
$item->enabled();

disabled

Disable the menu item.
$item->disabled();

visible

Set the visibility of the menu item.
visible
bool
default:"true"
Whether the menu item is visible
$item->visible(false);

checked

Set the checked state (for Checkbox and Radio items).
checked
bool
default:"true"
Whether the item is checked
$item->checked(true);

event

Set a Laravel event to dispatch when the menu item is clicked.
event
string
required
The event class name
$item->event('settings.opened');
Add a submenu to the menu item.
items
MenuItem...
required
Variable number of menu items
$item->submenu(
    Label::make('Preferences'),
    Label::make('About')
);

Build docs developers (and LLMs) love