mirror of
https://github.com/electron/electron.git
synced 2026-01-09 15:38:08 -05:00
feat: enable secondary label for macOS menu (#46887)
* feat: enable secondary label for macOS menu * Update shell/browser/ui/cocoa/electron_menu_controller.mm Co-authored-by: Robo <hop2deep@gmail.com> * fix for lint * update docs for sublabel --------- Co-authored-by: Robo <hop2deep@gmail.com>
This commit is contained in:
committed by
GitHub
parent
b9f0aebb2f
commit
10e4f9ad37
@@ -329,6 +329,27 @@ name, no matter what label you set. To change it, modify your app bundle's
|
||||
[About Information Property List Files][AboutInformationPropertyListFiles]
|
||||
for more information.
|
||||
|
||||
### Menu Sublabels
|
||||
|
||||
Menu sublabels, or [subtitles](https://developer.apple.com/documentation/appkit/nsmenuitem/subtitle?language=objc), can be added to menu items using the `sublabel` option. Below is an example based on the renderer example above:
|
||||
|
||||
```js @ts-expect-error=[12]
|
||||
// main
|
||||
ipcMain.on('show-context-menu', (event) => {
|
||||
const template = [
|
||||
{
|
||||
label: 'Menu Item 1',
|
||||
sublabel: 'Subtitle 1',
|
||||
click: () => { event.sender.send('context-menu-command', 'menu-item-1') }
|
||||
},
|
||||
{ type: 'separator' },
|
||||
{ label: 'Menu Item 2', sublabel: 'Subtitle 2', type: 'checkbox', checked: true }
|
||||
]
|
||||
const menu = Menu.buildFromTemplate(template)
|
||||
menu.popup({ window: BrowserWindow.fromWebContents(event.sender) })
|
||||
})
|
||||
```
|
||||
|
||||
## Setting Menu for Specific Browser Window (_Linux_ _Windows_)
|
||||
|
||||
The [`setMenu` method][setMenu] of browser windows can set the menu of certain
|
||||
|
||||
Reference in New Issue
Block a user