Skip to content

[WIKI-707] [WIKI-708] fix: editor floating ui modal#7909

Merged
pushya22 merged 3 commits intopreviewfrom
fix-editor_floating_ui
Oct 6, 2025
Merged

[WIKI-707] [WIKI-708] fix: editor floating ui modal#7909
pushya22 merged 3 commits intopreviewfrom
fix-editor_floating_ui

Conversation

@iam-vipin
Copy link
Member

@iam-vipin iam-vipin commented Oct 6, 2025

Description

  • Update the z-index value of the block menu for the issue overview.
  • Ensure the on-click handler is properly implemented to prevent the mention modal from closing unexpectedly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Screenshots and Media (if applicable)

Screen.Recording.2025-10-06.at.3.17.17.PM.mov

Test Scenarios

References

Summary by CodeRabbit

  • Bug Fixes

    • Interacting with the mentions dropdown no longer closes the surrounding modal; clicks and mouse actions inside the dropdown are now contained so selections remain stable.
    • Dropdown item selection reliably registers without accidental dismissal.
  • Style

    • Updated the block menu’s stacking order so it consistently appears above other UI elements.
    • Mentions dropdown is now positioned/attached to the page body for more accurate placement.

@iam-vipin iam-vipin requested review from aaryan610 and Copilot October 6, 2025 09:50
@iam-vipin iam-vipin added 🐛bug Something isn't working ✍️editor labels Oct 6, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes floating UI modal issues in the editor by addressing z-index conflicts and preventing unwanted modal closures. The changes ensure proper layering of UI elements and prevent event propagation that was causing modals to close unexpectedly.

  • Updated z-index handling for the block menu component
  • Added click event handler to prevent mention modal from closing unexpectedly

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/editor/src/core/extensions/mentions/utils.ts Added click event handler with stopPropagation to prevent modal closing
packages/editor/src/core/components/menus/block-menu.tsx Updated z-index from CSS class to inline style and removed conflicting z-20 class

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 36 to 38
element.addEventListener("click", (e) => {
e.stopPropagation();
});
Copy link

Copilot AI Oct 6, 2025

Choose a reason for hiding this comment

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

The event listener is added but never removed, which could lead to memory leaks. Consider storing the listener reference and removing it in the cleanup phase, or use a more specific event delegation pattern.

Copilot uses AI. Check for mistakes.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds visual stacking and DOM attachment for dropdowns and prevents event bubbling from the mentions dropdown; no public API changes.

Changes

Cohort / File(s) Summary of changes
BlockMenu z-index adjustment
packages/editor/src/core/components/menus/block-menu.tsx
Removes Tailwind z-20 from className and adds inline style zIndex: 100 to the BlockMenu container. Visual-only styling change.
Mentions dropdown mounting & positioning
packages/editor/src/core/extensions/mentions/utils.ts
On start, appends the mentions dropdown element to document.body and updates its position (new DOM attachment step). No API changes.
Mentions dropdown event handling
packages/editor/src/core/extensions/mentions/mentions-list-dropdown.tsx
Adds stopPropagation() on container click and mouseDown handlers and calls e.stopPropagation() in item click handler to prevent ancestor listeners from reacting. Adjusts interaction control flow for dropdown clicks.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant MentionsComponent as Mentions UI
  participant Utils as mentions/utils
  participant Dropdown as DropdownElement
  participant Document as document.body

  User->>MentionsComponent: open mention menu (hover/caret)
  MentionsComponent->>Utils: renderMentionsDropdown.onStart()
  Utils->>Dropdown: create & style dropdown
  Utils->>Document: append Dropdown to body
  Utils->>Dropdown: update position
  Note right of Dropdown: Event handlers added\nstopPropagation on click/mouseDown
  User->>Dropdown: click item
  Dropdown-->>Utils: stopPropagation prevents ancestor events
  Dropdown->>MentionsComponent: selectItem (item chosen)
  MentionsComponent->>User: insert mention
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

🌐frontend

Suggested reviewers

  • aaryan610
  • Palanikannan1437
  • pushya22

Poem

I nudged a menu, it climbed up high,
Appended to body, out of the sky.
Clicks stay local, they do not roam,
Stable selections, a cozy home.
— 🐇

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description includes the required sections for Description, Type of Change, and Screenshots but leaves the Test Scenarios and References headings empty, which the template marks as mandatory areas for detailing how changes were verified and linked. This omission means the description does not fully satisfy the repository’s template requirements. Please add concrete test scenarios describing the verification steps you ran to confirm the z‐index and click‐handling fixes, and include any relevant issue or design references under the References section.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title references the relevant issue keys and indicates a fix to the editor’s floating UI elements, which corresponds to the z‐index adjustment and mention dropdown behavior changes in this PR. Although the term “modal” is slightly imprecise for these menus, the title remains clearly related to the primary styling and interaction fixes.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-editor_floating_ui

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e09e1d3 and 8b0b8f6.

📒 Files selected for processing (2)
  • packages/editor/src/core/extensions/mentions/mentions-list-dropdown.tsx (2 hunks)
  • packages/editor/src/core/extensions/mentions/utils.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (3)
packages/editor/src/core/extensions/mentions/mentions-list-dropdown.tsx (2)

118-123: LGTM! Event suppression on container prevents unwanted closure.

Adding stopPropagation on both onClick and onMouseDown handlers prevents clicks inside the dropdown from bubbling to parent elements that might close it. This is a standard pattern for modal-like components and directly addresses the PR objective of preventing the mention modal from closing unexpectedly.


145-149: LGTM! stopPropagation ensures item selection doesn't trigger parent handlers.

The addition of e.stopPropagation() on line 147 prevents the click event from bubbling up after item selection, ensuring that any parent click handlers don't interfere with the selection process or prematurely close the dropdown. The existing e.preventDefault() on line 146 is correctly preserved.

packages/editor/src/core/extensions/mentions/utils.ts (1)

35-36: Approve dropdown attachment; verify z-index consistency
Attaching to document.body fixes stacking; positioning and cleanup via updateFloatingUIFloaterPosition and onExit are correct. Manually confirm that z-index 100 (line 33) aligns with other overlays/modals.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 0

♻️ Duplicate comments (1)
packages/editor/src/core/extensions/mentions/utils.ts (1)

36-38: Memory leak: Event listener never removed.

The click event listener prevents modal closure correctly but is never cleaned up. When the component is destroyed in onExit (lines 59-63), the element is removed from the DOM but the listener reference persists in memory.

Store the listener reference and remove it during cleanup:

 export const renderMentionsDropdown =
   (args: Pick<TMentionHandler, "searchCallback">): SuggestionOptions["render"] =>
   () => {
     const { searchCallback } = args;
     let component: ReactRenderer<CommandListInstance, MentionsListDropdownProps> | null = null;
+    let clickHandler: ((e: Event) => void) | null = null;

     return {
       onStart: (props) => {
         if (!searchCallback) return;
         if (!props.clientRect) return;
         component = new ReactRenderer<CommandListInstance, MentionsListDropdownProps>(MentionsListDropdown, {
           props: {
             ...props,
             searchCallback,
           },
           editor: props.editor,
         });
         props.editor.commands.addActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
         const element = component.element as HTMLElement;
         element.style.position = "absolute";
         element.style.zIndex = "100";

         // Add event handlers to prevent modal closing
-        element.addEventListener("click", (e) => {
+        clickHandler = (e) => {
           e.stopPropagation();
-        });
+        };
+        element.addEventListener("click", clickHandler);

         document.body.appendChild(element);
         updateFloatingUIFloaterPosition(props.editor, element);
       },
       onUpdate: (props) => {
         component?.updateProps(props);
         if (!props.clientRect) return;
         if (component?.element) {
           updateFloatingUIFloaterPosition(props.editor, component?.element as HTMLElement);
         }
       },
       onKeyDown: ({ event }) => {
         if (event.key === "Escape") {
           component?.destroy();
           component = null;
           return true;
         }

         return component?.ref?.onKeyDown({ event }) ?? false;
       },
       onExit: ({ editor }) => {
         editor.commands.removeActiveDropbarExtension(CORE_EXTENSIONS.MENTION);
+        if (component?.element && clickHandler) {
+          (component.element as HTMLElement).removeEventListener("click", clickHandler);
+        }
         component?.element.remove();
         component?.destroy();
+        clickHandler = null;
       },
     };
   };
🧹 Nitpick comments (1)
packages/editor/src/core/components/menus/block-menu.tsx (1)

209-212: LGTM! zIndex moved inline to 100 for block-menu, matching most floating UIs (floating menu, emoji list, link tooltip, table drag handles). Slash commands and mentions lists still use z-10—verify stacking when menus overlap or consolidate them to the same z-index scale.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c8f515 and e09e1d3.

📒 Files selected for processing (2)
  • packages/editor/src/core/components/menus/block-menu.tsx (1 hunks)
  • packages/editor/src/core/extensions/mentions/utils.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Build and lint web apps
  • GitHub Check: Analyze (javascript)

@pushya22 pushya22 merged commit 0cca31e into preview Oct 6, 2025
6 checks passed
@pushya22 pushya22 deleted the fix-editor_floating_ui branch October 6, 2025 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants