Skip to content

MenuItem

Properties

callback()?

optional callback: () => void

The callback that is executed when the menu item is clicked

Returns

void


checked

checked: null | boolean

Whether the menu item is checked


checkIconEl?

optional checkIconEl: HTMLElement

Check icon element of the menu item, only present if the item is checked


disabled

disabled: boolean

Whether the menu item is disabled


dom

dom: HTMLElement

Dom element of the menu item


iconEl

iconEl: HTMLElement

Icon element of the menu item


menu: Menu

Menu the item is in


section

section: string

The section the item belongs to


submenu: null | Menu

The submenu that is attached to the item


titleEl

titleEl: string

Title of the menu item

Methods

onClick()

onClick(callback): this

Parameters

callback

Returns

this


setChecked()

setChecked(checked): this

Parameters

checked: null | boolean

Returns

this


setDisabled()

setDisabled(disabled): this

Parameters

disabled: boolean

Returns

this


setIcon()

setIcon(icon): this

Parameters

icon: null | string

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

Returns

this

See

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


setIsLabel()

setIsLabel(isLabel): this

Parameters

isLabel: boolean

Returns

this


setSection()

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.

Parameters

section: string

Returns

this


setSubmenu()

setSubmenu(): Menu

Create a submenu on the menu item

Returns

Menu


setTitle()

setTitle(title): this

Parameters

title: string | DocumentFragment

Returns

this