Skip to content

Commit bae0640

Browse files
committed
Use nesting instead of refEl
1 parent 26db661 commit bae0640

File tree

3 files changed

+16
-25
lines changed

3 files changed

+16
-25
lines changed

packages/compass-components/src/components/content-with-fallback.spec.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ describe('ContentWithFallback', function () {
5959
);
6060

6161
expect(container.children.length).to.equal(1);
62-
expect(container.children[0].getAttribute('data-testid')).to.equal(
63-
'context-menu'
64-
);
62+
const [anchorElement] = container.children;
63+
expect(anchorElement.getAttribute('data-testid')).to.equal('context-menu');
6564
});
6665

6766
it('should render fallback when the timeout passes', async function () {

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useEffect, useMemo, useRef } from 'react';
2-
import { Menu, MenuItem, MenuSeparator, useEventListener } from './leafygreen';
2+
import { Menu, MenuItem, MenuSeparator } from './leafygreen';
33
import type { ContextMenuItem } from '@mongodb-js/compass-context-menu';
44
import { useContextMenu } from '@mongodb-js/compass-context-menu';
55
import { ContextMenuProvider as ContextMenuProviderBase } from '@mongodb-js/compass-context-menu';
@@ -22,7 +22,6 @@ export function ContextMenuProvider({
2222

2323
export function ContextMenu({ menu }: ContextMenuWrapperProps) {
2424
const menuRef = useRef(null);
25-
const anchorRef = useRef(null);
2625

2726
const position = menu.position;
2827
const itemGroups = menu.itemGroups;
@@ -34,22 +33,19 @@ export function ContextMenu({ menu }: ContextMenuWrapperProps) {
3433
}, [menu.isOpen]);
3534

3635
return (
37-
<>
38-
<div
39-
data-testid="context-menu-anchor"
40-
ref={anchorRef}
41-
style={{
42-
position: 'absolute',
43-
left: position.x,
44-
top: position.y,
45-
// This is to ensure the menu gets positioned correctly as the left and top updates
46-
width: 1,
47-
height: 1,
48-
}}
49-
/>
36+
<div
37+
data-testid="context-menu"
38+
style={{
39+
position: 'absolute',
40+
left: position.x,
41+
top: position.y,
42+
// This is to ensure the menu gets positioned correctly as the left and top updates
43+
width: 1,
44+
height: 1,
45+
}}
46+
>
5047
<Menu
5148
data-testid="context-menu"
52-
refEl={anchorRef}
5349
ref={menuRef}
5450
open={menu.isOpen}
5551
setOpen={menu.close}
@@ -92,7 +88,7 @@ export function ContextMenu({ menu }: ContextMenuWrapperProps) {
9288
}
9389
)}
9490
</Menu>
95-
</>
91+
</div>
9692
);
9793
}
9894

packages/compass-components/src/components/leafygreen.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,7 @@ import LeafyGreenTextInput from '@leafygreen-ui/text-input';
7272
import { SearchInput } from '@leafygreen-ui/search-input';
7373
export type { ToastProps } from '@leafygreen-ui/toast';
7474
export { ToastProvider, useToast } from '@leafygreen-ui/toast';
75-
export {
76-
usePrevious,
77-
useMergeRefs,
78-
useEventListener,
79-
} from '@leafygreen-ui/hooks';
75+
export { usePrevious, useMergeRefs } from '@leafygreen-ui/hooks';
8076
import Toggle from '@leafygreen-ui/toggle';
8177
import Tooltip from '@leafygreen-ui/tooltip';
8278
import {

0 commit comments

Comments
 (0)