āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā ā š shadcn/directory/udecode/plate/(plugins)/(functionality)/block-menu ā āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
title: Block Menu docs:
The fastest way to add the block menu is with the BlockMenuKit, which includes the pre-configured BlockMenuPlugin along with BlockSelectionPlugin and their Plate UI components.
BlockContextMenu: Renders the context menu interface.import { createPlateEditor } from 'platejs/react';
import { BlockMenuKit } from '@/components/editor/plugins/block-menu-kit';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
...BlockMenuKit,
],
});
</Steps>
npm install @platejs/selection
The block menu requires both BlockSelectionPlugin and BlockMenuPlugin to function properly.
import { BlockSelectionPlugin, BlockMenuPlugin } from '@platejs/selection/react';
import { createPlateEditor } from 'platejs/react';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
BlockSelectionPlugin.configure({
options: {
enableContextMenu: true,
},
}),
BlockMenuPlugin,
],
});
Configure the block menu with a context menu component:
import { BlockSelectionPlugin, BlockMenuPlugin } from '@platejs/selection/react';
import { createPlateEditor } from 'platejs/react';
import { BlockContextMenu } from '@/components/ui/block-context-menu';
const editor = createPlateEditor({
plugins: [
// ...otherPlugins,
BlockSelectionPlugin.configure({
options: {
enableContextMenu: true,
},
}),
BlockMenuPlugin.configure({
render: { aboveEditable: BlockContextMenu },
}),
],
});
BlockSelectionPlugin.options.enableContextMenu: Enables the context menu functionality.BlockMenuPlugin.render.aboveEditable: Assigns BlockContextMenu to render the context menu.To control the opening of the context menu for specific elements, use the data-plate-open-context-menu attribute:
<PlateElement data-plate-open-context-menu={false} {...props}>
{children}
</PlateElement>
This is commonly used to prevent right-clicking on the padding of the <Editor /> component from opening the menu.
BlockMenuPluginPlugin for block menu state management and context menu functionality.
api.blockMenu.hideHides the block menu.
api.blockMenu.showShows the block menu for a specific block.
<API name="show"> <APIParameters> <APIItem name="id" type="'context' | string"> The ID of the block to show the menu for, or 'context' for the context menu. </APIItem> <APIItem name="position" type="{ x: number; y: number }" optional> The position to show the menu at. If not provided, only the openId is updated. </APIItem> </APIParameters> </API>api.blockMenu.showContextMenuShows the context menu for a specific block and automatically selects that block.
<API name="showContextMenu"> <APIParameters> <APIItem name="blockId" type="string"> The ID of the block to show the context menu for. </APIItem> <APIItem name="position" type="{ x: number; y: number }"> The position to show the context menu at. </APIItem> </APIParameters> </API>ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā ā
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā