Docs
Block Menu

Block Menu

Provides quick access to block-specific actions.

Block Menu

The Block Menu provides quick access to actions for individual blocks. You can open this menu by right-clicking on any block in the editor.
Key features of the Block Context Menu:
  • Right-click on any block to open the menu
  • Try using block selection to select multiple blocks, then open the menu for the selected blocks.
  • When you try to right-click the block at the cursor's location, the default menu will open.This allows users to use browser extensions or paste plain text, etc.
  • Options to duplicate, delete, or other what you want
  • Transform blocks into different types

Features

  • Right-click on a block to open the menu.
  • Allows you to perform actions on blocks such as turn into, duplicating or deleting.
  • Customizable menu items and actions.
  • Keyboard navigation

Installation

npm install @udecode/plate-selection @udecode/plate-node-id

Usage

import { BlockMenuPlugin } from '@udecode/plate-selection/react';
import { NodeIdPlugin } from '@udecode/plate-node-id';
const plugins = [
  // ...otherPlugins,
  NodeIdPlugin,
  BlockSelectionPlugin.configure({
    options: {
      areaOptions: {
        behaviour: {
          scrolling: {
            speedDivider: 1.5,
          },
          startThreshold: 10,
        },
        boundaries: '#scroll_container',
        container: '#scroll_container',
        selectables: '#scroll_container .slate-selectable',
        selectionAreaClass: 'slate-selection-area',
      },
      enableContextMenu: true,
    },
  }),
  BlockMenuPlugin.configure({
    render: { aboveEditable: BlockContextMenu },
  }),
]

To control the opening of the context menu for specific elements, you can use the data-plate-open-context-menu attribute:

<PlateElement data-plate-open-context-menu={false} {...props}>
  {children}
</PlateElement>

Generally, we only need to prevent right-clicking on the padding of the <Editor />.

Examples

Plate UI

Refer to the preview above.

Plate Plus

  • Open the menu via the drag button or the three-dot menu on specific blocks (e.g. images)
  • Includes a combobox that filters options as you type
  • Supports nested menu options
  • Advanced actions such as "Ask AI", colors, and commenting
  • Beautifully crafted UI

Plugins

BlockMenuPlugin

Block menu state management.

API

editor.api.blockMenu.hide

Hides the block menu.

editor.api.blockMenu.show

Shows the block menu for a specific block.

Parameters

Collapse all

    The ID of the block to show the menu for.

    The position to show the menu at.

editor.api.blockMenu.showContextMenu

Shows the context menu for a specific block.

Parameters

Collapse all

    The ID of the block to show the context menu for.

    The position to show the context menu at.