Overview
TheBubbleMenu component renders a contextual menu that appears near the user’s text selection. It’s commonly used for formatting toolbars that appear when text is selected, similar to Medium or Google Docs.
Signature
Props
Editor
required
The Tiptap editor instance. This prop is required.
string | PluginKey
default:"'bubbleMenu'"
A unique key for the ProseMirror plugin. Use this if you need multiple bubble menus or want to identify this specific plugin.
number
default:"undefined"
Delay in milliseconds before updating the menu position after a selection change. Useful for debouncing rapid selection changes.
number
default:"undefined"
Delay in milliseconds before updating the menu position after a window resize event.
TippyOptions
default:"{}"
Configuration options for the underlying Tippy.js positioning library. Use this to customize the menu’s placement, offset, animation, and other display properties.Common options:
placement- Position relative to reference (e.g., ‘top’, ‘bottom’, ‘left’, ‘right’)offset- Distance from the reference elementduration- Animation durationzIndex- CSS z-index value
Element | (() => Element) | 'parent'
default:"undefined"
The element to append the bubble menu to. Can be:
- A DOM element
- A function that returns a DOM element
- The string
'parent'to append to the editor’s parent element
document.body.function
default:"null"
A callback function that determines whether the bubble menu should be visible. Receives an object with:
editor- The editor instanceview- The ProseMirror EditorViewstate- Current editor stateoldState- Previous editor statefrom- Start position of selectionto- End position of selection
true to show the menu, false to hide it.By default, the menu shows when there’s a text selection and hides when the selection is empty.function
default:"undefined"
A function that returns a custom reference element for positioning. Use this to position the menu relative to a specific element or virtual element instead of the text selection.Receives the same props as
shouldShow and should return a DOMRect, Range, or Tippy.js VirtualElement.Lifecycle
- onMounted: Registers the bubble menu plugin with the editor and sets up positioning
- onBeforeUnmount: Unregisters the plugin from the editor
Styling
The component inherits attributes (inheritAttrs: false is set, but attributes are manually applied), allowing you to add custom classes, styles, or other HTML attributes:
Examples
Basic Usage
Styled Bubble Menu
Custom shouldShow Logic
With Tippy Options
Multiple Bubble Menus
Notes
- The bubble menu is automatically positioned near the text selection using Tippy.js
- By default, it shows only when there’s a non-empty text selection
- The component renders as a
<div>element that you can style with classes or inline styles - Multiple bubble menus can coexist by using different
pluginKeyvalues - The menu is removed from the DOM and re-parented by the plugin when shown
- Use
shouldShowto customize when the menu appears based on editor state
See Also
- FloatingMenu - Menu for empty lines
- useEditor - Create editor instances
- EditorContent - Render the editor