MenuItem
Defined in: obsidian.d.ts:2720
Properties
Section titled “Properties”checked
Section titled “checked”checked:
null
|boolean
Defined in: src/obsidian/augmentations/MenuItem.d.ts:13
Whether the menu item is checked.
checkIconEl?
Section titled “checkIconEl?”
optional
checkIconEl:HTMLElement
Defined in: src/obsidian/augmentations/MenuItem.d.ts:20
Check icon element of the menu item, only present if the item is checked.
disabled
Section titled “disabled”disabled:
boolean
Defined in: src/obsidian/augmentations/MenuItem.d.ts:27
Whether the menu item is disabled.
dom:
HTMLElement
Defined in: src/obsidian/augmentations/MenuItem.d.ts:34
Dom element of the menu item.
iconEl
Section titled “iconEl”iconEl:
HTMLElement
Defined in: src/obsidian/augmentations/MenuItem.d.ts:41
Icon element of the menu item.
menu:
Menu
Defined in: src/obsidian/augmentations/MenuItem.d.ts:48
Menu the item is in.
section
Section titled “section”section:
string
Defined in: src/obsidian/augmentations/MenuItem.d.ts:55
The section the item belongs to.
submenu
Section titled “submenu”submenu:
null
|Menu
Defined in: src/obsidian/augmentations/MenuItem.d.ts:62
The submenu that is attached to the item.
titleEl
Section titled “titleEl”titleEl:
HTMLElement
Defined in: src/obsidian/augmentations/MenuItem.d.ts:69
Title of the menu item.
Methods
Section titled “Methods”callback()?
Section titled “callback()?”
optional
callback():void
Defined in: src/obsidian/augmentations/MenuItem.d.ts:76
The callback that is executed when the menu item is clicked.
Returns
Section titled “Returns”void
constructor__()?
Section titled “constructor__()?”
optional
constructor__():this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:84
Private constructor. Use Menu.addItem instead.
Returns
Section titled “Returns”this
handleEvent()
Section titled “handleEvent()”handleEvent(
e
):void
Defined in: src/obsidian/augmentations/MenuItem.d.ts:92
Executes the callback of the onClick event (if not disabled).
Parameters
Section titled “Parameters”Mouse or keyboard event.
Returns
Section titled “Returns”void
onClick()
Section titled “onClick()”Call Signature
Section titled “Call Signature”onClick(
callback
):this
Defined in: obsidian.d.ts:2755
Parameters
Section titled “Parameters”callback
Section titled “callback”(evt
) => any
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”onClick(
callback
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:107
Set the callback function to be called when the menu item is clicked.
Parameters
Section titled “Parameters”callback
Section titled “callback”(evt
) => any
The callback function.
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.onClick(() => { console.log('Menu item clicked');});
removeIcon()
Section titled “removeIcon()”removeIcon():
void
Defined in: src/obsidian/augmentations/MenuItem.d.ts:114
Remove the icon element from the menu item.
Returns
Section titled “Returns”void
setActive()
Section titled “setActive()”setActive(
active
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:123
Calls setChecked
, prefer usage of that function instead.
Parameters
Section titled “Parameters”active
Section titled “active”boolean
Whether the menu item should be checked.
Returns
Section titled “Returns”this
setChecked()
Section titled “setChecked()”Call Signature
Section titled “Call Signature”setChecked(
checked
):this
Defined in: obsidian.d.ts:2741
Parameters
Section titled “Parameters”checked
Section titled “checked”null
| boolean
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”setChecked(
checked
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:136
Set the checked state of the menu item.
Parameters
Section titled “Parameters”checked
Section titled “checked”Whether the menu item is checked.
null
| boolean
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.setChecked(true);
setDisabled()
Section titled “setDisabled()”Call Signature
Section titled “Call Signature”setDisabled(
disabled
):this
Defined in: obsidian.d.ts:2745
Parameters
Section titled “Parameters”disabled
Section titled “disabled”boolean
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”setDisabled(
disabled
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:149
Set the disabled state of the menu item.
Parameters
Section titled “Parameters”disabled
Section titled “disabled”boolean
Whether the menu item is disabled.
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.setDisabled(true);
setIcon()
Section titled “setIcon()”Call Signature
Section titled “Call Signature”setIcon(
icon
):this
Defined in: obsidian.d.ts:2736
Parameters
Section titled “Parameters”ID of the icon, can use any icon loaded with addIcon or from the built-in lucide library.
null
| string
Returns
Section titled “Returns”this
The Obsidian icon library includes the Lucide icon library, any icon name from their site will work here.
Call Signature
Section titled “Call Signature”setIcon(
icon
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:163
Set the icon of the menu item.
Parameters
Section titled “Parameters”ID of the icon, can use any icon loaded with addIcon or from the built-in lucide library.
null
| string
Returns
Section titled “Returns”this
The menu item instance.
The Obsidian icon library includes the Lucide icon library, any icon name from their site will work here.
Example
Section titled “Example”menuItem.setIcon('dice');
setIsLabel()
Section titled “setIsLabel()”Call Signature
Section titled “Call Signature”setIsLabel(
isLabel
):this
Defined in: obsidian.d.ts:2750
Parameters
Section titled “Parameters”isLabel
Section titled “isLabel”boolean
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”setIsLabel(
isLabel
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:176
Set the menu item to be a label.
Parameters
Section titled “Parameters”isLabel
Section titled “isLabel”boolean
Whether the menu item is a label.
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.setIsLabel(true);
setSection()
Section titled “setSection()”Call Signature
Section titled “Call Signature”setSection(
section
):this
Defined in: obsidian.d.ts:2763
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.
Parameters
Section titled “Parameters”section
Section titled “section”string
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”setSection(
section
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:191
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.
Parameters
Section titled “Parameters”section
Section titled “section”string
The section of the menu item.
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.setSection('danger');
setSubmenu()
Section titled “setSubmenu()”setSubmenu():
Menu
Defined in: src/obsidian/augmentations/MenuItem.d.ts:199
Create a submenu on the menu item.
Returns
Section titled “Returns”setTitle()
Section titled “setTitle()”Call Signature
Section titled “Call Signature”setTitle(
title
):this
Defined in: obsidian.d.ts:2730
Parameters
Section titled “Parameters”string
| DocumentFragment
Returns
Section titled “Returns”this
Call Signature
Section titled “Call Signature”setTitle(
title
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:216
Set the title of the menu item.
Parameters
Section titled “Parameters”The title of the menu item.
string
| DocumentFragment
Returns
Section titled “Returns”this
The menu item instance.
Example
Section titled “Example”menuItem.setTitle('foo');
const fragment = createFragment();fragment.createEl('strong', { text: 'bar' });menuItem.setTitle(fragment);
setWarning()
Section titled “setWarning()”setWarning(
warning
):this
Defined in: src/obsidian/augmentations/MenuItem.d.ts:224
Add warning styling to the menu item.
Parameters
Section titled “Parameters”warning
Section titled “warning”boolean
Whether the menu item should be styled as a warning.
Returns
Section titled “Returns”this