1- import React , { useEffect , useMemo , useRef } from 'react' ;
1+ import React , { useMemo , useRef } from 'react' ;
22import { Menu , MenuItem , MenuSeparator } from './leafygreen' ;
3-
43import { css } from '@leafygreen-ui/emotion' ;
54import { spacing } from '@leafygreen-ui/tokens' ;
65
@@ -14,9 +13,11 @@ import {
1413
1514export type { ContextMenuItem } from '@mongodb-js/compass-context-menu' ;
1615
16+ // TODO: Remove these once https://jira.mongodb.org/browse/LG-5013 is resolved
17+
1718const menuStyles = css ( {
18- paddingTop : spacing [ 100 ] ,
19- paddingBottom : spacing [ 100 ] ,
19+ paddingTop : spacing [ 150 ] ,
20+ paddingBottom : spacing [ 150 ] ,
2021} ) ;
2122
2223const itemStyles = css ( {
@@ -39,33 +40,39 @@ export function ContextMenuProvider({
3940
4041export function ContextMenu ( { menu } : ContextMenuWrapperProps ) {
4142 const menuRef = useRef ( null ) ;
43+ const anchorRef = useRef < HTMLDivElement > ( null ) ;
4244
4345 const { position, itemGroups } = menu ;
4446
45- useEffect ( ( ) => {
46- if ( ! menu . isOpen ) {
47- menu . close ( ) ;
48- }
49- } , [ menu . isOpen ] ) ;
47+ // TODO: Remove when https://jira.mongodb.org/browse/LG-5342 is resolved
48+ if ( anchorRef . current ) {
49+ anchorRef . current . style . left = ` ${ position . x } px` ;
50+ anchorRef . current . style . top = ` ${ position . y } px` ;
51+ }
5052
5153 return (
52- < div
53- data-testid = "context-menu"
54- style = { {
55- position : 'absolute' ,
56- left : position . x ,
57- top : position . y ,
58- // This is to ensure the menu gets positioned correctly as the left and top updates
59- width : 1 ,
60- height : 1 ,
61- } }
62- >
54+ < div data-testid = "context-menu-container" >
55+ < div
56+ data-testid = "context-menu-anchor"
57+ ref = { anchorRef }
58+ style = { {
59+ position : 'absolute' ,
60+ left : position . x ,
61+ top : position . y ,
62+ // This is to ensure the menu gets positioned correctly as the left and top updates
63+ width : 1 ,
64+ height : 1 ,
65+ } }
66+ />
6367 < Menu
68+ data-testid = "context-menu"
69+ refEl = { anchorRef }
6470 ref = { menuRef }
6571 open = { menu . isOpen }
6672 setOpen = { menu . close }
6773 justify = "start"
6874 className = { menuStyles }
75+ maxHeight = { Number . MAX_SAFE_INTEGER }
6976 >
7077 { itemGroups . map ( ( items : ContextMenuItemGroup , groupIndex : number ) => {
7178 return (
0 commit comments