Skip to content

[WIKI-505] fix: bubble menu floating ui #7282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: preview
Choose a base branch
from

Conversation

Palanikannan1437
Copy link
Member

@Palanikannan1437 Palanikannan1437 commented Jun 29, 2025

Description

Added floating UI in Bubble menu, with proper positioning while selecting

Summary by CodeRabbit

  • New Features

    • Introduced a contextual bubble menu for the editor, providing quick access to formatting and editing tools.
    • Added a React component for the bubble menu, enabling seamless integration and rendering outside the main DOM hierarchy.
    • Integrated a new extension to manage the bubble menu’s lifecycle and configuration within the editor.
  • Refactor

    • Updated alignment, color, link, and node selector components to use standardized UI elements and improved styling.
    • Simplified and reorganized the bubble menu’s internal structure for better maintainability and user experience.
  • Style

    • Enhanced animations and transitions for alignment buttons and icons, resulting in smoother visual feedback.

Copy link
Contributor

coderabbitai bot commented Jun 29, 2025

Walkthrough

This update introduces a modular, plugin-based bubble menu system for a TipTap-based editor. It adds a new BubbleMenu plugin, a React renderer, and a TipTap extension to manage contextual menus. Several bubble menu UI components are refactored to use standardized popover and menu libraries, and the main bubble menu root component is streamlined for clarity.

Changes

File(s) Summary
.../bubble-menu/alignment-selector.tsx Updated container and button styles, enhanced transitions, and conditional icon coloring; logic unchanged.
.../bubble-menu/color-selector.tsx
.../bubble-menu/link-selector.tsx
Refactored to use @headlessui/react Popover for menu control, removing manual state and conditional rendering.
.../bubble-menu/node-selector.tsx Switched from custom dropdown to CustomMenu from @plane/ui; removed manual open state and simplified item selection.
.../bubble-menu/root.tsx Simplified structure, removed selection tracking state, reorganized layout, and updated prop types for the main bubble menu.
.../bubble-menu/bubble-menu-plugin.ts New: Implements a Bubble Menu plugin for TipTap/ProseMirror, managing lifecycle, positioning, and events with Floating UI.
.../bubble-menu/bubble-menu-renderer.tsx New: Adds a React component that manages a detached DOM node for the bubble menu and registers the plugin with the editor.
.../bubble-menu/bubble-menu.ts New: Introduces a TipTap extension for the bubble menu, registering the plugin and managing configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Editor (TipTap)
    participant BubbleMenuPlugin
    participant BubbleMenu (React)
    participant DOM

    User->>Editor (TipTap): Selects text / triggers selection
    Editor (TipTap)->>BubbleMenuPlugin: Notifies selection change
    BubbleMenuPlugin->>BubbleMenu (React): Requests menu update/show
    BubbleMenu (React)->>DOM: Renders/positions bubble menu
    User->>BubbleMenu (React): Interacts with menu (e.g., format, link, color)
    BubbleMenu (React)->>Editor (TipTap): Executes formatting commands
Loading

Poem

🐇
A bubble menu floats with grace,
Refactored menus in their place.
Popovers pop, selectors gleam,
Plugins join the editing team.
With React and TipTap hand in hand,
The editor’s UI is simply grand!
— A jubilant code rabbit

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Palanikannan1437 Palanikannan1437 force-pushed the fix/bubble-menu-floating-ui branch from 34fc608 to eb0281b Compare June 29, 2025 17:43
@Palanikannan1437 Palanikannan1437 marked this pull request as ready for review June 30, 2025 09:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (2)
packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (1)

32-32: Consider removing unused isOpen prop from component interface.

The isOpen prop is still declared in the Props type (line 27) but is no longer destructured or used since CustomMenu manages its own open state internally.

 type Props = {
   editor: Editor;
-  isOpen: boolean;
   setIsOpen: Dispatch<SetStateAction<boolean>>;
 };
packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts (1)

328-331: Specify delay parameter in setTimeout for clarity.

The setTimeout call should explicitly specify the delay parameter for better code clarity.

-    setTimeout(() => this.update(this.editor.view));
+    setTimeout(() => this.update(this.editor.view), 0);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a065e1 and eb0281b.

📒 Files selected for processing (8)
  • packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/bubble-menu-renderer.tsx (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/bubble-menu.ts (1 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (3 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (2 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (3 hunks)
  • packages/editor/src/core/components/menus/bubble-menu/root.tsx (3 hunks)
🧰 Additional context used
🧠 Learnings (1)
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (1)
Learnt from: vineetk13
PR: makeplane/plane#6391
File: web/styles/react-day-picker.css:249-282
Timestamp: 2025-01-17T05:17:51.953Z
Learning: In the date range picker's CSS, left/right positioning for cell background effects (like in `.rdp-range_start::before`, `.rdp-range_middle::before`, `.rdp-range_end::before`) should use physical properties instead of logical properties, as these create visual effects that should remain consistent regardless of text direction.
🧬 Code Graph Analysis (2)
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (1)
packages/utils/src/common.ts (1)
  • cn (8-8)
packages/editor/src/core/components/menus/bubble-menu/bubble-menu.ts (1)
packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts (2)
  • BubbleMenuPluginProps (30-114)
  • BubbleMenuPlugin (531-535)
🔇 Additional comments (12)
packages/editor/src/core/components/menus/bubble-menu/alignment-selector.tsx (2)

60-60: Good styling improvement for vertical alignment.

The addition of items-center ensures proper vertical centering of the alignment buttons, and the padding adjustment provides better visual spacing.


70-70: Excellent transition enhancements for better UX.

The addition of transition classes (transition-all duration-200 ease-in-out for buttons and transition-transform duration-200 for icons) provides smooth hover and active state animations. The conditional styling for active icons ensures consistent visual feedback.

Also applies to: 76-80

packages/editor/src/core/components/menus/bubble-menu/bubble-menu.ts (2)

5-12: Well-designed type definition.

The BubbleMenuOptions type correctly omits editor and element from the plugin props while making element nullable, which allows for flexible usage patterns where the DOM element might not be immediately available.


30-44: Good defensive programming with conditional plugin registration.

The null check for this.options.element before registering the plugin prevents runtime errors and follows the pattern where extensions should gracefully handle missing dependencies.

packages/editor/src/core/components/menus/bubble-menu/bubble-menu-renderer.tsx (2)

17-21: Correct ref forwarding implementation.

The ref forwarding logic properly handles both function and object refs, ensuring the created div element is accessible to parent components.


65-65: Good use of portals for bubble menu rendering.

Using createPortal allows the bubble menu to render outside the normal React tree hierarchy, which is appropriate for floating UI elements that need to avoid z-index and overflow issues.

packages/editor/src/core/components/menus/bubble-menu/color-selector.tsx (2)

28-67: Excellent refactor to use Headless UI Popover.

The migration to Popover component improves code maintainability by removing manual state management and provides better accessibility features out of the box. The button styling and structure are well-organized with proper conditional classes for open states.


68-119: Well-structured color selection panels.

The color selection UI is properly organized within Popover.Panel with clear sections for text and background colors. The color buttons maintain their functionality while the clear buttons (with Ban icon) provide intuitive color removal options.

packages/editor/src/core/components/menus/bubble-menu/node-selector.tsx (1)

54-84: Great refactor to use CustomMenu component.

The migration to CustomMenu significantly reduces boilerplate code while maintaining the existing functionality. The custom button implementation preserves the visual design, and the menu items properly handle commands and state updates with correct event propagation control.

packages/editor/src/core/components/menus/bubble-menu/link-selector.tsx (1)

1-116: LGTM! Clean refactoring to use Popover component.

The migration to @headlessui/react's Popover component simplifies state management and follows consistent UI patterns. The URL validation and error handling are properly maintained.

packages/editor/src/core/components/menus/bubble-menu/root.tsx (1)

1-179: LGTM! Excellent simplification of the bubble menu component.

The refactoring effectively removes manual selection tracking in favor of the plugin-based approach. The shouldShow logic is comprehensive, and the component structure is cleaner with better separation of concerns.

packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts (1)

120-536: Well-architected bubble menu plugin implementation.

The plugin demonstrates excellent practices:

  • Comprehensive event handling with proper cleanup in destroy()
  • Performance optimization through debouncing
  • Clean separation between selection tracking and menu positioning
  • Proper TypeScript typing throughout

The Floating UI integration provides flexible positioning options, and the special handling for cell selections is a nice touch.

Comment on lines +23 to +63
useEffect(() => {
const bubbleMenuElement = menuEl.current;

bubbleMenuElement.style.visibility = "hidden";
bubbleMenuElement.style.position = "absolute";

if (editor?.isDestroyed) {
return;
}

const attachToEditor = editor;

if (!attachToEditor) {
console.warn(
"BubbleMenu component is not rendered inside of an editor component or does not have editor prop."
);
return;
}

const plugin = BubbleMenuPlugin({
updateDelay,
resizeDelay,
editor: attachToEditor,
element: bubbleMenuElement,
pluginKey,
shouldShow,
options,
});

attachToEditor.registerPlugin(plugin);

return () => {
attachToEditor.unregisterPlugin(pluginKey);
window.requestAnimationFrame(() => {
if (bubbleMenuElement.parentNode) {
bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
}
});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editor]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix missing dependencies in useEffect.

The useEffect uses several props (pluginKey, updateDelay, resizeDelay, shouldShow, options) but only includes editor in the dependency array. This could cause stale closures when these props change.

-      // eslint-disable-next-line react-hooks/exhaustive-deps
-    }, [editor]);
+    }, [editor, pluginKey, updateDelay, resizeDelay, shouldShow, options]);

If options is an object that changes reference on every render, consider memoizing it or restructuring to avoid unnecessary re-registrations.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
useEffect(() => {
const bubbleMenuElement = menuEl.current;
bubbleMenuElement.style.visibility = "hidden";
bubbleMenuElement.style.position = "absolute";
if (editor?.isDestroyed) {
return;
}
const attachToEditor = editor;
if (!attachToEditor) {
console.warn(
"BubbleMenu component is not rendered inside of an editor component or does not have editor prop."
);
return;
}
const plugin = BubbleMenuPlugin({
updateDelay,
resizeDelay,
editor: attachToEditor,
element: bubbleMenuElement,
pluginKey,
shouldShow,
options,
});
attachToEditor.registerPlugin(plugin);
return () => {
attachToEditor.unregisterPlugin(pluginKey);
window.requestAnimationFrame(() => {
if (bubbleMenuElement.parentNode) {
bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
}
});
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [editor]);
useEffect(() => {
const bubbleMenuElement = menuEl.current;
bubbleMenuElement.style.visibility = "hidden";
bubbleMenuElement.style.position = "absolute";
if (editor?.isDestroyed) {
return;
}
const attachToEditor = editor;
if (!attachToEditor) {
console.warn(
"BubbleMenu component is not rendered inside of an editor component or does not have editor prop."
);
return;
}
const plugin = BubbleMenuPlugin({
updateDelay,
resizeDelay,
editor: attachToEditor,
element: bubbleMenuElement,
pluginKey,
shouldShow,
options,
});
attachToEditor.registerPlugin(plugin);
return () => {
attachToEditor.unregisterPlugin(pluginKey);
window.requestAnimationFrame(() => {
if (bubbleMenuElement.parentNode) {
bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
}
});
};
}, [editor, pluginKey, updateDelay, resizeDelay, shouldShow, options]);
🤖 Prompt for AI Agents
In
packages/editor/src/core/components/menus/bubble-menu/bubble-menu-renderer.tsx
between lines 23 and 63, the useEffect hook depends on multiple props like
pluginKey, updateDelay, resizeDelay, shouldShow, and options, but only editor is
listed in the dependency array. To fix this, add all these props to the
dependency array to ensure the effect runs correctly when any of them change. If
options is an object that changes reference frequently, memoize it or
restructure the code to prevent unnecessary effect executions and plugin
re-registrations.

Comment on lines +481 to +496
show() {
if (this.isVisible) {
return;
}

this.element.style.visibility = "visible";
this.element.style.opacity = "1";
// attach to editor's parent element
this.view.dom.parentElement?.appendChild(this.element);

if (this.floatingUIOptions.onShow) {
this.floatingUIOptions.onShow();
}

this.isVisible = true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add null check before DOM manipulation.

The element might not be appended if parentElement is null. Consider adding a fallback or explicit check.

 show() {
   if (this.isVisible) {
     return;
   }

   this.element.style.visibility = "visible";
   this.element.style.opacity = "1";
-  // attach to editor's parent element
-  this.view.dom.parentElement?.appendChild(this.element);
+  // attach to editor's parent element
+  const parentElement = this.view.dom.parentElement;
+  if (parentElement) {
+    parentElement.appendChild(this.element);
+  } else {
+    console.warn("Unable to attach bubble menu: editor parent element not found");
+  }

   if (this.floatingUIOptions.onShow) {
     this.floatingUIOptions.onShow();
   }

   this.isVisible = true;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
show() {
if (this.isVisible) {
return;
}
this.element.style.visibility = "visible";
this.element.style.opacity = "1";
// attach to editor's parent element
this.view.dom.parentElement?.appendChild(this.element);
if (this.floatingUIOptions.onShow) {
this.floatingUIOptions.onShow();
}
this.isVisible = true;
}
show() {
if (this.isVisible) {
return;
}
this.element.style.visibility = "visible";
this.element.style.opacity = "1";
// attach to editor's parent element
const parentElement = this.view.dom.parentElement;
if (parentElement) {
parentElement.appendChild(this.element);
} else {
console.warn("Unable to attach bubble menu: editor parent element not found");
}
if (this.floatingUIOptions.onShow) {
this.floatingUIOptions.onShow();
}
this.isVisible = true;
}
🤖 Prompt for AI Agents
In packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts
around lines 481 to 496, the code appends this.element to
this.view.dom.parentElement without confirming parentElement is not null. Add an
explicit null check for this.view.dom.parentElement before calling appendChild
to avoid errors when parentElement is null. If parentElement is null, skip the
appendChild call or handle the fallback appropriately.

Comment on lines +18 to +28
function combineDOMRects(rect1: DOMRect, rect2: DOMRect): DOMRect {
const top = Math.min(rect1.top, rect2.top);
const bottom = Math.max(rect1.bottom, rect2.bottom);
const left = Math.min(rect1.left, rect2.left);
const right = Math.max(rect1.right, rect2.right);
const width = right - left;
const height = bottom - top;
const x = left;
const y = top;
return new DOMRect(x, y, width, height);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Check browser compatibility for DOMRect constructor.

The DOMRect constructor is not supported in older browsers (e.g., IE, older versions of Safari). Consider using a polyfill or creating an object that mimics DOMRect.

Apply this diff for better browser compatibility:

-function combineDOMRects(rect1: DOMRect, rect2: DOMRect): DOMRect {
+function combineDOMRects(rect1: DOMRect, rect2: DOMRect): DOMRect {
   const top = Math.min(rect1.top, rect2.top);
   const bottom = Math.max(rect1.bottom, rect2.bottom);
   const left = Math.min(rect1.left, rect2.left);
   const right = Math.max(rect1.right, rect2.right);
   const width = right - left;
   const height = bottom - top;
   const x = left;
   const y = top;
-  return new DOMRect(x, y, width, height);
+  
+  // For better browser compatibility
+  const rect = {
+    x,
+    y,
+    width,
+    height,
+    top,
+    right,
+    bottom,
+    left,
+    toJSON() {
+      return { x, y, width, height, top, right, bottom, left };
+    }
+  };
+  
+  return rect as DOMRect;
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function combineDOMRects(rect1: DOMRect, rect2: DOMRect): DOMRect {
const top = Math.min(rect1.top, rect2.top);
const bottom = Math.max(rect1.bottom, rect2.bottom);
const left = Math.min(rect1.left, rect2.left);
const right = Math.max(rect1.right, rect2.right);
const width = right - left;
const height = bottom - top;
const x = left;
const y = top;
return new DOMRect(x, y, width, height);
}
function combineDOMRects(rect1: DOMRect, rect2: DOMRect): DOMRect {
const top = Math.min(rect1.top, rect2.top);
const bottom = Math.max(rect1.bottom, rect2.bottom);
const left = Math.min(rect1.left, rect2.left);
const right = Math.max(rect1.right, rect2.right);
const width = right - left;
const height = bottom - top;
const x = left;
const y = top;
// For better browser compatibility
const rect = {
x,
y,
width,
height,
top,
right,
bottom,
left,
toJSON() {
return { x, y, width, height, top, right, bottom, left };
}
};
return rect as DOMRect;
}
🤖 Prompt for AI Agents
In packages/editor/src/core/components/menus/bubble-menu/bubble-menu-plugin.ts
around lines 18 to 28, the code uses the DOMRect constructor which lacks support
in older browsers like IE and some Safari versions. To fix this, replace the
DOMRect constructor with an object literal that mimics the DOMRect properties
(x, y, width, height, top, bottom, left, right) to ensure compatibility across
all browsers without relying on the constructor.

@Palanikannan1437 Palanikannan1437 changed the title fix: bubble menu floating ui [WIKI-505] fix: bubble menu floating ui Jun 30, 2025
Copy link

makeplane bot commented Jun 30, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@Palanikannan1437 Palanikannan1437 marked this pull request as draft July 1, 2025 11:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant