Class: FSubmenu
This is the builder for add a menu that can contains submenus to Univer. You shall
never construct this class by yourself. Instead, call createSubmenu
of FUniver to
create a instance.
Please notice that until the appendTo
method is called, the menu item is not added to the UI.
Extends
FMenuBase
Methods
addSeparator()
addSeparator(): this
Add a separator to the submenu.
Returns
this
The FSubmenu itself for chaining calls.
Example
// Create two leaf menus.
const menu1 = univerAPI.createMenu({
id: 'submenu-nested-1',
title: 'Item 1',
action: () => {
console.log('Item 1 clicked');
}
});
const menu2 = univerAPI.createMenu({
id: 'submenu-nested-2',
title: 'Item 2',
action: () => {
console.log('Item 2 clicked');
}
});
// Add the leaf menus to a submenu and add a separator between them.
// Append the submenu to the `contextMenu.others` section.
univerAPI.createSubmenu({ id: 'submenu-nested', title: 'Nested Submenu' })
.addSubmenu(menu1)
.addSeparator()
.addSubmenu(menu2)
.appendTo('contextMenu.others');
addSubmenu()
addSubmenu(submenu): this
Add a menu to the submenu. It can be a FMenu or a FSubmenu.
Parameters
Parameter | Type | Description |
---|---|---|
submenu | FMenu | FSubmenu | Menu to add to the submenu. |
Returns
this
The FSubmenu itself for chaining calls.
Example
// Create two leaf menus.
const menu1 = univerAPI.createMenu({
id: 'submenu-nested-1',
title: 'Item 1',
action: () => {
console.log('Item 1 clicked');
}
});
const menu2 = univerAPI.createMenu({
id: 'submenu-nested-2',
title: 'Item 2',
action: () => {
console.log('Item 2 clicked');
}
});
// Add the leaf menus to a submenu.
const submenu = univerAPI.createSubmenu({ id: 'submenu-nested', title: 'Nested Submenu' })
.addSubmenu(menu1)
.addSeparator()
.addSubmenu(menu2);
// Create a root submenu append to the `contextMenu.others` section.
univerAPI.createSubmenu({ id: 'custom-submenu', title: 'Custom Submenu' })
.addSubmenu(submenu)
.appendTo('contextMenu.others');