Skip to content

ckeditor5-elements / ElementContextMenu

Class: ElementContextMenu ​

Shows the menu of an element when the user right-clicks it, or opens the context menu with the keyboard (the menu key, or Shift+F10) while the cursor is in it.

The items come from the elementContextMenu editor config option only (see ElementMenuConfig): commands, submenus and '|' separators. Without it, or when it returns no items for an element, the native context menu shows. The menu itself is shown by the ElementMenu plugin.

Extends ​

Constructors ​

Constructor ​

ts
new ElementContextMenu(editor): ElementContextMenu;

Parameters ​

ParameterType
editorEditor

Returns ​

ElementContextMenu

Inherit Doc ​

Inherited from ​

Plugin.constructor

Accessors ​

pluginName ​

Get Signature ​

ts
get static pluginName(): "ElementContextMenu";
Returns ​

"ElementContextMenu"


requires ​

Get Signature ​

ts
get static requires(): readonly [typeof ElementMenu];
Returns ​

readonly [typeof ElementMenu]

Methods ​

getModelElement() ​

ts
getModelElement(viewElement): 
  | ModelElement
  | null;

Returns the closest model element mapped to the given view element or its ancestors, skipping the root.

Parameters ​

ParameterType
viewElementViewElement

Returns ​

| ModelElement | null


init() ​

ts
init(): void;

Returns ​

void


open() ​

ts
open(element, target): boolean;

Opens the menu of the element next to the target (e.g. a button, or a DOMRect in viewport coordinates), with the items from the elementContextMenu config option.

Returns false when there are no items, so the caller can let the native context menu show instead.

Parameters ​

ParameterType
elementModelElement
targetRectSource

Returns ​

boolean


openAtSelection() ​

ts
openAtSelection(): boolean;

Opens the menu of the element at the selection (the selected element, or the element with the cursor), next to the selection.

Returns false when there is no such element or no items.

Returns ​

boolean