Skip to content

Conversation

@kraenhansen
Copy link
Contributor

@kraenhansen kraenhansen commented Jul 1, 2025

Description

Merging this PR will:

  • Use a separate anchor ref instead of nesting the menu under the trigger, to allow it updating its height as expected.
  • Force use of a compact menu styling (until we have LG-5013).

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)

@kraenhansen kraenhansen requested a review from gagik July 1, 2025 14:49
@kraenhansen kraenhansen self-assigned this Jul 1, 2025
Copilot AI review requested due to automatic review settings July 1, 2025 14:49
@kraenhansen kraenhansen requested a review from a team as a code owner July 1, 2025 14:49
@kraenhansen kraenhansen added no release notes Fix or feature not for release notes no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion) labels Jul 1, 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 refactors the context menu to use an external anchor element for positioning, applies temporary compact styling, and updates related tests to reflect the new data-testid attributes.

  • Switches from nesting the menu under its trigger to an absolutely positioned anchor ref
  • Applies compact menu and item CSS overrides via Emotion
  • Updates tests to query context-menu-container instead of the old context-menu id, and adjusts ContentWithFallback tests accordingly

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
context-menu.tsx Introduce anchorRef, remove useEffect, add compact CSS classes
context-menu.spec.tsx Change selector to [data-testid="context-menu-container"]
content-with-fallback.spec.tsx Update test description/assertion to context-menu-container and add an unused import
Comments suppressed due to low confidence (1)

packages/compass-components/src/components/context-menu.tsx:74

  • The new menuStyles and itemStyles compact overrides aren’t currently asserted in any tests. Consider adding a test to verify that these classes are applied correctly to the menu and items.
        className={menuStyles}

Comment on lines +48 to +51
if (anchorRef.current) {
anchorRef.current.style.left = `${position.x}px`;
anchorRef.current.style.top = `${position.y}px`;
}
Copy link

Copilot AI Jul 1, 2025

Choose a reason for hiding this comment

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

Updating anchorRef.current.style directly on every render can lead to unnecessary DOM writes. Consider wrapping these updates in a useLayoutEffect that only runs when position changes.

Suggested change
if (anchorRef.current) {
anchorRef.current.style.left = `${position.x}px`;
anchorRef.current.style.top = `${position.y}px`;
}
React.useLayoutEffect(() => {
if (anchorRef.current) {
anchorRef.current.style.left = `${position.x}px`;
anchorRef.current.style.top = `${position.y}px`;
}
}, [position]);

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, we have to do this outside of a useEffect or useLayoutEffect for it to work.

@kraenhansen kraenhansen changed the title Use anchor ref and compact menu chore(context-menu) use anchor ref and compact menu Jul 1, 2025
@kraenhansen kraenhansen force-pushed the kh/use-anchor-ref-and-compact-menu branch from 66beb5b to 2f57140 Compare July 1, 2025 15:29
@kraenhansen kraenhansen changed the title chore(context-menu) use anchor ref and compact menu chore(context-menu): use anchor ref and compact menu Jul 1, 2025
menu.close();
}
}, [menu.isOpen]);
// TODO: Remove when https://jira.mongodb.org/browse/LG-5342 is resolved
Copy link
Member

Choose a reason for hiding this comment

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

If we want to address this when that ticket is resolved, we can create a ticket marked as Blocked and link the tickets as depends upon. Then when it's resolved that ticket will get set to open and we get reminded of it.

Fine as is, I figured I'd mention in case you haven't done that flow before.

@kraenhansen kraenhansen merged commit f4fbe29 into main Jul 2, 2025
61 checks passed
@kraenhansen kraenhansen deleted the kh/use-anchor-ref-and-compact-menu branch July 2, 2025 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no release notes Fix or feature not for release notes no-title-validation Skips validation of PR titles (conventional commit adherence + JIRA ticket inclusion)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants