Overview
TheFloatingMenu component renders a menu that appears when the cursor is on an empty line in the editor. It’s commonly used to provide quick access to block-level formatting options like headings, lists, or inserting media.
Type Signature
Props
Editor | null
required
The editor instance. If not provided, the component will attempt to use the editor from React context via
useCurrentEditor.string | PluginKey
default:"'floatingMenu'"
Unique identifier for this floating menu plugin. Use different keys if you have multiple floating menus.
number
default:"250"
Delay in milliseconds before the menu position is updated. This debounces position updates for better performance.
number
default:"60"
Delay in milliseconds before the menu position is updated on window resize. This debounces resize events for better performance.
function | null
default:"null"
Function that determines whether the menu should be shown. Receives editor state and selection information.Default behavior: Shows when the cursor is in an empty text block at the root level and the editor has focus.
HTMLElement | (() => HTMLElement)
The DOM element to append the menu to. Useful when you need to render the menu in a specific container for z-index or overflow reasons.Default: The editor’s parent element.
object
Floating UI configuration options for positioning and behavior.
React.ReactNode
required
The content to render inside the floating menu.
React.HTMLAttributes<HTMLDivElement>
All standard HTML div attributes (className, style, etc.) are supported.
Usage Examples
Basic Usage
Block Type Selector
Styled Floating Menu
Custom shouldShow Logic
Slash Command Style
With Icons
Custom Positioning
Styling
CSS Example
Notion-Style Plus Button
Important Notes
The FloatingMenu uses Floating UI for positioning, which provides intelligent placement that avoids overflow and adjusts to viewport constraints.
Default Behavior
By default, the floating menu:- Shows when the cursor is in an empty text block at root depth
- Hides when text is typed
- Hides when the editor loses focus
- Positions itself to the right of the cursor
- Only appears when the editor is editable
- In empty list items
- In code blocks
- In nested content
- When text exists in the block
- When the editor doesn’t have focus
Comparison with BubbleMenu
Related
- BubbleMenu - Menu for selected text
- useEditor - Hook for creating editor instances
- Floating UI Documentation - Advanced positioning options