Skip to content

Commit 2781efc

Browse files
Update multi-level menu example to include MacOS gotchas (#3407)
Co-authored-by: FabianLars <[email protected]>
1 parent 551ac89 commit 2781efc

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/content/docs/learn/window-menu.mdx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,30 @@ fn main() {
143143

144144
## Creating a multi-level menu
145145

146-
To create a multi-level menu, you can add some submenus to the menu item:
146+
Multi-level menus allow you to group menu items under categories like "File," "Edit," etc. These will appear as part of the application window for Windows or Linux, or in the menu bar on MacOS.
147+
148+
**Note:** When using submenus on MacOS, all items must be grouped under a submenu. Top-level items will be ignored. Additionally, the first submenu will be placed under the application's about menu by default, regardless of the `text` label. You should include a submenu as the first entry (say, an "About" submenu) to fill this space.
147149

148150
<Tabs>
149151
<TabItem label="JavaScript">
150152

151153
```javascript
152154
import { Menu, MenuItem, Submenu } from '@tauri-apps/api/menu';
153155

156+
// Will become the application submenu on MacOS
157+
const aboutSubmenu = await Submenu.new({
158+
text: 'About',
159+
items: [
160+
await MenuItem.new({
161+
id: 'quit',
162+
text: 'Quit',
163+
action: () => {
164+
console.log('Quit pressed');
165+
},
166+
}),
167+
],
168+
});
169+
154170
const fileSubmenu = await Submenu.new({
155171
text: 'File',
156172
items: [
@@ -199,17 +215,7 @@ const editSubmenu = await Submenu.new({
199215
});
200216

201217
const menu = await Menu.new({
202-
items: [
203-
fileSubmenu,
204-
editSubmenu,
205-
await MenuItem.new({
206-
id: 'quit',
207-
text: 'Quit',
208-
action: () => {
209-
console.log('Quit pressed');
210-
},
211-
}),
212-
],
218+
items: [aboutSubmenu, fileSubmenu, editSubmenu],
213219
});
214220

215221
menu.setAsAppMenu();

0 commit comments

Comments
 (0)