Overview
TheBubbleMenu component renders a contextual menu that appears when text is selected in the editor. It’s positioned using Floating UI and provides a flexible way to show formatting options or other tools near the selection.
Type Signature
Props
Editor | null
The editor instance. If not provided, the component will attempt to use the editor from React context via
useCurrentEditor.string | PluginKey
default:"'bubbleMenu'"
Unique identifier for this bubble menu plugin. Use different keys if you have multiple bubble 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 there’s a non-empty text selection 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.
() => VirtualElement | null
Function that returns a custom virtual element for positioning. Useful for custom positioning logic.Default: Positions based on the current selection.
object
Floating UI configuration options for positioning and behavior.
React.ReactNode
required
The content to render inside the bubble menu.
React.HTMLAttributes<HTMLDivElement>
All standard HTML div attributes (className, style, etc.) are supported.
Usage Examples
Basic Usage
With Custom Styling
Custom shouldShow Logic
Multiple Bubble Menus
With Active States
With Custom Positioning
Styling
CSS Example
Important Notes
The BubbleMenu uses Floating UI for positioning, which provides intelligent placement that avoids overflow and adjusts to viewport constraints.
Default Behavior
By default, the bubble menu:- Shows when text is selected
- Hides when the selection is empty
- Hides when the editor loses focus (unless focus moves to an element inside the menu)
- Positions itself above the selection
- Automatically adjusts position when the viewport is too small
Related
- FloatingMenu - Menu that appears in empty lines
- useEditor - Hook for creating editor instances
- Floating UI Documentation - Advanced positioning options