macOS menu bar
Build the native macOS menu bar from Compose, with items, shortcuts, icons, badges, and submenus that follow your state.
menu-macos builds the native macOS menu bar from Compose. You declare menus and items as a tree,
and the bar updates when the state it reads changes. NativeMenuBar does nothing on Windows and
Linux, so the call can stay in shared code.
menu-macosGradle plugin: Not neededWindow runtime: Not neededAdd the dependency
dependencies {
implementation("dev.nucleusframework:nucleus.menu-macos:3.0.0")
}It brings sf-symbols for typed icon names.
Build a menu bar
fun main() = nucleusApplication {
NativeMenuBar {
Menu("MyApp") {
Item("About MyApp") { showAbout() }
Separator()
Item("Quit MyApp", shortcut = NativeKeyShortcut("q")) { exitApplication() }
}
Menu("File") {
Item(
"New",
shortcut = NativeKeyShortcut("n"),
icon = NsMenuItemImage.SystemSymbol(SFSymbolObjectsAndTools.DOCUMENT_BADGE_PLUS),
) { newDocument() }
Menu("Recent") {
Item("notes.md") { open("notes.md") }
}
}
MenuWindow("Window")
MenuHelp("Help") {
Item("Documentation") { openDocs() }
}
}
// Windows
}- The first
Menubecomes the application menu, the bold entry named after your app. AMenuinside aMenuis a submenu. - Keep
NativeMenuBaroutside any window's content, so the bar stays while windows open and close. - macOS fills
MenuWindow(window list, Bring All to Front) andMenuHelp(search field); their content is optional. - Click handlers run on the UI thread and can change Compose state.

Handle Cmd+Q
Without a Cmd+Q item, Cmd+Q runs the built-in quit, which asks each window's onCloseRequest. An
item bound to NativeKeyShortcut("q") takes the shortcut over: Cmd+Q runs its action instead, so
confirm unsaved work there.
- Quit with
exitApplication().exitProcessskips closing the windows. - While the item is disabled, Cmd+Q beeps and does nothing.
Add checkboxes and radio buttons
You hold the state; the item shows the checkmark:
var darkMode by remember { mutableStateOf(false) }
Menu("View") {
CheckboxItem("Dark mode", checked = darkMode, onCheckedChange = { darkMode = it })
Separator()
RadioButtonItem("Light", selected = !darkMode, onClick = { darkMode = false })
RadioButtonItem("Dark", selected = darkMode, onClick = { darkMode = true })
}Add search and section headers
Menu("History") {
SearchField(placeholder = "Search history")
SectionHeader("Today")
Item("nucleusframework.dev") { open(url) }
}SearchField filters the menu's items by title as the user types. SectionHeader needs macOS 14
and falls back to a disabled item on older systems.
API reference
Item(text) { onClick } parameters:
| Parameter | Effect |
|---|---|
enabled | Grey the item out when false |
shortcut | NativeKeyShortcut(key): Command by default; add shift, option, control, function, or command = false. NativeKey holds ESCAPE, RETURN, TAB, DELETE, BACKSPACE, arrow keys and more |
icon | NsMenuItemImage.SystemSymbol (an SFSymbol or raw name, macOS 11+), Named (AppKit or bundle image), or File |
state | NsMenuItemState.OFF, ON, or MIXED |
badge | NsMenuItemBadge.Count, Text, or the localized Alerts, NewItems, Updates (macOS 14+) |
subtitle | Second line under the title (macOS 14.4+) |
toolTip / tag / indentationLevel | Hover text / integer tag / indentation |
isAlternate | Show in place of the previous item while its modifier is held |
isHidden | Hide the item but keep its key equivalent |
onStateImage, offStateImage, mixedStateImage | Replace the checkmark per state |
Menu also accepts an icon.
What's next
- SF Symbols: typed names for
SystemSymbolicons. - Context menus: native right-click menus inside your windows.
- Application entry point: how Cmd+Q and Dock > Quit reach your windows.
Last updated on