Skip to content

fix: scrolling the context menu shouldn't close it COMPASS-9584 #7172

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

Merged
merged 2 commits into from
Aug 7, 2025

Conversation

paula-stacho
Copy link
Contributor

Description

stopPropagation doesn't work because the eventListener on window gets triggered first due to the capture option. I assume the capture was intentional and shouldn't be removed (correct me if I'm wrong @gagik ), but it's okay because we can just do this - ignore based on the target.

Screen.Recording.2025-08-06.at.22.49.15.mov

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

@Copilot Copilot AI review requested due to automatic review settings August 6, 2025 20:49
@paula-stacho paula-stacho requested a review from a team as a code owner August 6, 2025 20:49
@github-actions github-actions bot added the fix label Aug 6, 2025
@paula-stacho paula-stacho requested a review from gagik August 6, 2025 20:50
Copy link
Contributor

@Copilot 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 an issue where scrolling within a context menu would incorrectly close the menu. The fix involves checking if the scroll event originates from within the context menu itself before closing it.

  • Adds a CSS class name constant for identifying context menu elements
  • Modifies the scroll event handler to ignore scroll events from within the context menu
  • Applies the CSS class to the context menu component for identification

Reviewed Changes

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

File Description
packages/compass-context-menu/src/index.ts Exports the new contextMenuClassName constant
packages/compass-context-menu/src/context-menu-provider.tsx Updates scroll event handler to check if scroll target is within context menu
packages/compass-context-menu/src/consts.ts Defines the contextMenuClassName constant
packages/compass-components/src/components/context-menu.tsx Applies the contextMenuClassName to the menu component

(e) => {
const isCompassContextMenu =
e.target instanceof HTMLElement &&
e.target.classList.contains(contextMenuClassName);
Copy link
Preview

Copilot AI Aug 6, 2025

Choose a reason for hiding this comment

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

The check only verifies if the direct target has the contextMenuClassName. Consider using element.closest() to check if the scroll target is within any ancestor element that has the contextMenuClassName, as scroll events might originate from child elements within the context menu.

Suggested change
e.target.classList.contains(contextMenuClassName);
e.target.closest('.' + contextMenuClassName);

Copilot uses AI. Check for mistakes.

Copy link

Assigned himanshusinghs for team compass-developers because gagik is out of office.

@gagik
Copy link
Contributor

gagik commented Aug 7, 2025

Yeah the capture was intentional because we generally want to close the right click menu whenever it gets scrolled on any other item. Otherwise it'd end up floating awkwardly as you scroll.

Copy link
Contributor

@gagik gagik left a comment

Choose a reason for hiding this comment

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

Seems reasonable to me! Thanks for looking into it.

@paula-stacho paula-stacho merged commit 5deaca4 into main Aug 7, 2025
57 of 60 checks passed
@paula-stacho paula-stacho deleted the COMPASS-9584 branch August 7, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants