Skip to main content
The FloatingMenu extension provides a menu that appears when the cursor is in an empty line at the root level. It’s commonly used for slash commands, block insertion menus, or quick formatting options. The menu is positioned using Floating UI and supports custom visibility rules.

Installation

Basic Usage

Vanilla JavaScript

React

Vue

Configuration Options

HTMLElement
required
The DOM element that contains your menu.Default: null
PluginKey | string
The plugin key for the floating menu.Default: 'floatingMenu'
number
The delay in milliseconds before the menu position should be updated. This can be useful to prevent performance issues.Default: 250
number
The delay in milliseconds before the menu position should be updated on window resize.Default: 60
function
A function that determines whether the menu should be shown or not. The default implementation shows the menu when the cursor is in an empty text block at the root level.Parameters:
  • editor: The editor instance
  • view: The ProseMirror EditorView
  • state: The current editor state
  • oldState: The previous editor state (optional)
  • from: Selection start position
  • to: Selection end position
Default behavior:
  • Shows when editor has focus
  • Selection is empty (cursor, not range)
  • Cursor is at root depth (depth === 1)
  • Current block is empty text block
  • Editor is editable
HTMLElement | (() => HTMLElement)
The DOM element to append your menu to. Sometimes the menu needs to be appended to a different DOM context due to accessibility, clipping, or z-index issues.Default: Editor’s parent element
object
Configuration options passed to Floating UI for positioning. See Floating UI documentation for full details.Properties:
'absolute' | 'fixed'
Positioning strategy.Default: 'absolute'
string
Menu placement relative to cursor. Options: 'top', 'right', 'bottom', 'left', 'top-start', 'top-end', 'right-start', 'right-end', 'bottom-start', 'bottom-end', 'left-start', 'left-end'Default: 'right'
number | object | boolean
Distance in pixels from the cursor.Default: 8
object | boolean
Whether to flip the menu to the opposite side if there’s not enough space.Default: {}
object | boolean
Whether to shift the menu along the axis to keep it in view.Default: {}
HTMLElement | Window
The scrollable element that should be listened to when updating the position.Default: window
() => void
Callback fired when the menu is shown.
() => void
Callback fired when the menu is hidden.
() => void
Callback fired when the menu position is updated.
() => void
Callback fired when the menu is destroyed.

Commands

command
Manually update the position of the floating menu.

React Component Props

When using the React component, you can pass these props:
Editor
The editor instance. Can be omitted if used inside EditorProvider.
string
The plugin key.Default: 'floatingMenu'
number
Update delay in milliseconds.
number
Resize delay in milliseconds.
function
Function to determine visibility.
object
Floating UI configuration options.
Plus all standard HTML div attributes (className, style, etc.).

Vue Component Props

Editor
required
The editor instance.
string
The plugin key.Default: 'floatingMenu'
number
Update delay in milliseconds.
number
Resize delay in milliseconds.
function
Function to determine visibility.
object
Floating UI configuration options.
HTMLElement | Function
Element to append the menu to.

Advanced Examples

Slash Command Menu

Show in Nested Blocks

Update Position Programmatically

Custom Positioning

Multiple Floating Menus

Source Code

View the source code on GitHub: