MenuItem
Official
A menu item.
Import:
import { MenuItem } from 'obsidian';Signature:
export class MenuItemConstructor
new MenuItem(menu: unknown)Constructor.
To get the constructor instance, use getMenuItemConstructor from obsidian-typings/implementations.
Properties
| Property | Type | Description | |
|---|---|---|---|
| checked | boolean | null | Whether the menu item is checked. | |
| checkIconEl? | HTMLElement | Check icon element of the menu item, only present if the item is checked. | |
| disabled | boolean | Whether the menu item is disabled. | |
| dom | HTMLElement | Dom element of the menu item. | |
| iconEl | HTMLElement | Icon element of the menu item. | |
| menu | Menu | obsidian#Menu the item is in. | |
| section | string | The section the item belongs to. | |
| submenu | Menu | null | The submenu that is attached to the item. | |
| titleEl | HTMLElement | Title of the menu item. |
Methods
| Method | Returns | Description | |
|---|---|---|---|
| callback() | void | The callback that is executed when the menu item is clicked. | |
| handleEvent(e) | void | Executes the callback of the onClick event (if not disabled). | |
| onClick(callback) | this | Set the callback function to be called when the menu item is clicked. | |
| removeIcon() | void | Remove the icon element from the menu item. | |
| setActive(active) | this | Calls setChecked, prefer usage of that function instead. | |
| setChecked(checked) | this | Set the checked state of the menu item. | |
| setDisabled(disabled) | this | Set the disabled state of the menu item. | |
| setIcon(icon) | this | Set the icon of the menu item. | |
| setIsLabel(isLabel) | this | Set the menu item to be a label. | |
| setSection(section) | this | Sets the section this menu item should belong in. To find the section IDs of an existing menu, inspect the DOM elements to see their data-section attribute. | |
| setSubmenu() | Menu | Create a submenu on the menu item. | |
| setTitle(title) | this | Set the title of the menu item. | |
| setWarning(warning) | this | Add warning styling to the menu item. |
Links to this page: