The MarkupEditor logo

Class: MenuItem

MenuItem(spec)

An icon or label that, when clicked, executes a command.

Modified from: prosemirror-menu

Constructor

Create a menu item. The following items are supported in the MenuItem spec:

  • The function to execute when the menu item is activated.

    run: (state: EditorState, dispatch: (tr: Transaction) => void, view: EditorView, event: Event) => void

  • Optional function that is used to determine whether the item is appropriate at the moment. Deselected items will be hidden.

    select?: (state: EditorState) => boolean

  • Function that is used to determine if the item is enabled. If given and returning false, the item will be given a disabled styling.

    enable?: (state: EditorState) => boolean

  • A predicate function to determine whether the item is 'active' (for example, the item for toggling the strong mark might be active then the cursor is in strong text).

    active?: (state: EditorState) => boolean

  • A function that renders the item. You must provide either this, icon, or label.

    render?: (view: EditorView) => HTMLElement

  • Describes an icon to show for this item using SVG.

    icon?: string

  • Makes the item show up as a text label. Mostly useful for items wrapped in a drop-down or similar menu. The object should have a label property providing the text to display.

    label?: string

  • Defines DOM title (mouseover) text for the item.

    title?: string | ((state: EditorState) => string)

  • Optionally adds a CSS class to the item's DOM representation.

    class?: string

  • Optionally adds a string of inline CSS to the item's DOM representation.

    css?: string

Parameters:
Name Type Description
spec object

The spec used to create this item. See list above.

Classes

MenuItem

Methods

render(view)

Renders the item according to the spec, and adds an event handler which executes the command when the representation is clicked.

Parameters:
Name Type Description
view EditorView

The view to render this MenuItem in.

Table of contents