Skip to content

ContextMenu

ContextMenu is a module to help patch and create context menus. Instance is accessible through the BdApi.

Properties

Methods

buildItem

Builds a single menu item. The only prop shown here is the type, the rest should match the actual component being built. View those to see what options exist for each, they often have less in common than you might think.

ParameterTypeOptionalDefaultDescription
propsobjectnoneProps used to build the item
props.typestring"text"Type of the item, options: text, submenu, toggle, radio, custom, separator

Returns: object - The created component


buildMenu

Creates the menu component including the wrapping ContextMenu. Calls {@link ContextMenu.buildMenuChildren} under the covers. Used to call in combination with {@link ContextMenu.open}.

ParameterTypeDescription
setupArray.<object>Array of item props used to build items. See {@link ContextMenu.buildMenuChildren}.

Returns: function - The unique context menu component


buildMenuChildren

Creates the all the items and groups of a context menu recursively. There is no hard limit to the number of groups within groups or number of items in a menu.

ParameterTypeDescription
setupArray.<object>Array of item props used to build items. See {@link ContextMenu.buildItem}.

Returns: Array.<object> - Array of the created component


close

Closes the current opened context menu immediately.

Returns: void


open

Function that allows you to open an entire context menu. Recommended to build the menu with this module.

ParameterTypeOptionalDefaultDescription
eventMouseEventnoneThe context menu event. This can be emulated, requires target, and all X, Y locations.
menuComponentfunctionnoneComponent to render. This can be any React component or output of {@link ContextMenu.buildMenu}.
configobjectnoneConfiguration/props for the context menu
config.positionstring"right"Default position for the menu, options: "left", "right"
config.alignstring"top"Default alignment for the menu, options: "bottom", "top"
config.onClosefunctionnoneFunction to run when the menu is closed

Returns: void


patch

Allows you to patch a given context menu. Acts as a wrapper around the Patcher.

ParameterTypeDescription
navIdstringDiscord's internal navId used to identify context menus
callbackfunctionCallback function that accepts the React render tree

Returns: function - A function that automatically unpatches


unpatch

Allows you to remove the patch added to a given context menu.

ParameterTypeDescription
navIdstringThe original navId from patching
callbackfunctionThe original callback from patching

Returns: void