Skip to content

MenuItem

Defined in: obsidian.d.ts:2720

checked: null | boolean

Defined in: src/obsidian/augmentations/MenuItem.d.ts:13

Whether the menu item is checked.

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: 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: 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: string

Defined in: src/obsidian/augmentations/MenuItem.d.ts:55

The section the item belongs to.

submenu: null | Menu

Defined in: src/obsidian/augmentations/MenuItem.d.ts:62

The submenu that is attached to the item.

titleEl: HTMLElement

Defined in: src/obsidian/augmentations/MenuItem.d.ts:69

Title of the menu item.

optional callback(): void

Defined in: src/obsidian/augmentations/MenuItem.d.ts:76

The callback that is executed when the menu item is clicked.

void

optional constructor__(): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:84

Private constructor. Use Menu.addItem instead.

this

handleEvent(e): void

Defined in: src/obsidian/augmentations/MenuItem.d.ts:92

Executes the callback of the onClick event (if not disabled).

Mouse or keyboard event.

MouseEvent | KeyboardEvent

void

onClick(callback): this

Defined in: obsidian.d.ts:2755

(evt) => any

this

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.

(evt) => any

The callback function.

this

The menu item instance.

menuItem.onClick(() => {
console.log('Menu item clicked');
});

removeIcon(): void

Defined in: src/obsidian/augmentations/MenuItem.d.ts:114

Remove the icon element from the menu item.

void

setActive(active): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:123

Calls setChecked, prefer usage of that function instead.

boolean

Whether the menu item should be checked.

this

setChecked(checked): this

Defined in: obsidian.d.ts:2741

null | boolean

this

setChecked(checked): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:136

Set the checked state of the menu item.

Whether the menu item is checked.

null | boolean

this

The menu item instance.

menuItem.setChecked(true);

setDisabled(disabled): this

Defined in: obsidian.d.ts:2745

boolean

this

setDisabled(disabled): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:149

Set the disabled state of the menu item.

boolean

Whether the menu item is disabled.

this

The menu item instance.

menuItem.setDisabled(true);

setIcon(icon): this

Defined in: obsidian.d.ts:2736

ID of the icon, can use any icon loaded with addIcon or from the built-in lucide library.

null | string

this

The Obsidian icon library includes the Lucide icon library, any icon name from their site will work here.

setIcon(icon): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:163

Set the icon of the menu item.

ID of the icon, can use any icon loaded with addIcon or from the built-in lucide library.

null | string

this

The menu item instance.

The Obsidian icon library includes the Lucide icon library, any icon name from their site will work here.

menuItem.setIcon('dice');

setIsLabel(isLabel): this

Defined in: obsidian.d.ts:2750

boolean

this

setIsLabel(isLabel): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:176

Set the menu item to be a label.

boolean

Whether the menu item is a label.

this

The menu item instance.

menuItem.setIsLabel(true);

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.

string

this

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.

string

The section of the menu item.

this

The menu item instance.

menuItem.setSection('danger');

setSubmenu(): Menu

Defined in: src/obsidian/augmentations/MenuItem.d.ts:199

Create a submenu on the menu item.

Menu

setTitle(title): this

Defined in: obsidian.d.ts:2730

string | DocumentFragment

this

setTitle(title): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:216

Set the title of the menu item.

The title of the menu item.

string | DocumentFragment

this

The menu item instance.

menuItem.setTitle('foo');
const fragment = createFragment();
fragment.createEl('strong', { text: 'bar' });
menuItem.setTitle(fragment);

setWarning(warning): this

Defined in: src/obsidian/augmentations/MenuItem.d.ts:224

Add warning styling to the menu item.

boolean

Whether the menu item should be styled as a warning.

this