Skip to content

MenuItem

Official

A menu item.

Import:

import { MenuItem } from 'obsidian';

Signature:

export class MenuItem

Constructor

new MenuItem(menu: unknown)

Constructor.

To get the constructor instance, use getMenuItemConstructor from obsidian-typings/implementations.

Properties

PropertyTypeDescription
checkedboolean | nullWhether the menu item is checked.
checkIconEl?HTMLElementCheck icon element of the menu item, only present if the item is checked.
disabledbooleanWhether the menu item is disabled.
domHTMLElementDom element of the menu item.
iconElHTMLElementIcon element of the menu item.
menuMenuobsidian#Menu the item is in.
sectionstringThe section the item belongs to.
submenuMenu | nullThe submenu that is attached to the item.
titleElHTMLElementTitle of the menu item.

Methods

MethodReturnsDescription
callback()voidThe callback that is executed when the menu item is clicked.
handleEvent(e)voidExecutes the callback of the onClick event (if not disabled).
onClick(callback)thisSet the callback function to be called when the menu item is clicked.
removeIcon()voidRemove the icon element from the menu item.
setActive(active)thisCalls setChecked, prefer usage of that function instead.
setChecked(checked)thisSet the checked state of the menu item.
setDisabled(disabled)thisSet the disabled state of the menu item.
setIcon(icon)thisSet the icon of the menu item.
setIsLabel(isLabel)thisSet the menu item to be a label.
setSection(section)thisSets 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()MenuCreate a submenu on the menu item.
setTitle(title)thisSet the title of the menu item.
setWarning(warning)thisAdd warning styling to the menu item.

Links to this page: