Nucleus
OS integrationMenus

macOS menu bar

Build the native macOS menu bar from Compose, with items, shortcuts, icons, badges, and submenus that follow your state.

View as Markdown

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-macosmacOSGradle plugin: Not neededWindow runtime: Not needed

Add the dependency

build.gradle.kts
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 Menu becomes the application menu, the bold entry named after your app. A Menu inside a Menu is a submenu.
  • Keep NativeMenuBar outside any window's content, so the bar stays while windows open and close.
  • macOS fills MenuWindow (window list, Bring All to Front) and MenuHelp (search field); their content is optional.
  • Click handlers run on the UI thread and can change Compose state.

A native macOS menu with a shortcut, a badge, a section header, a radio group and a submenu

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(). exitProcess skips 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:

ParameterEffect
enabledGrey the item out when false
shortcutNativeKeyShortcut(key): Command by default; add shift, option, control, function, or command = false. NativeKey holds ESCAPE, RETURN, TAB, DELETE, BACKSPACE, arrow keys and more
iconNsMenuItemImage.SystemSymbol (an SFSymbol or raw name, macOS 11+), Named (AppKit or bundle image), or File
stateNsMenuItemState.OFF, ON, or MIXED
badgeNsMenuItemBadge.Count, Text, or the localized Alerts, NewItems, Updates (macOS 14+)
subtitleSecond line under the title (macOS 14.4+)
toolTip / tag / indentationLevelHover text / integer tag / indentation
isAlternateShow in place of the previous item while its modifier is held
isHiddenHide the item but keep its key equivalent
onStateImage, offStateImage, mixedStateImageReplace the checkmark per state

Menu also accepts an icon.

What's next

Was this page helpful?
Edit on GitHub

Last updated on