File tree Expand file tree Collapse file tree 4 files changed +16
-3
lines changed
compass-components/src/components Expand file tree Collapse file tree 4 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1
1
import React , { useMemo , useRef } from 'react' ;
2
2
import { Menu , MenuItem , MenuSeparator } from './leafygreen' ;
3
- import { css } from '@leafygreen-ui/emotion' ;
3
+ import { css , cx } from '@leafygreen-ui/emotion' ;
4
4
import { spacing } from '@leafygreen-ui/tokens' ;
5
5
6
6
import {
9
9
type ContextMenuItem ,
10
10
type ContextMenuItemGroup ,
11
11
type ContextMenuWrapperProps ,
12
+ contextMenuClassName ,
12
13
} from '@mongodb-js/compass-context-menu' ;
13
14
14
15
export type {
@@ -76,7 +77,7 @@ export function ContextMenu({ menu }: ContextMenuWrapperProps) {
76
77
open = { menu . isOpen }
77
78
setOpen = { menu . close }
78
79
justify = "start"
79
- className = { menuStyles }
80
+ className = { cx ( menuStyles , contextMenuClassName ) }
80
81
maxHeight = { Number . MAX_SAFE_INTEGER }
81
82
>
82
83
{ itemGroups . map ( ( items : ContextMenuItemGroup , groupIndex : number ) => {
Original file line number Diff line number Diff line change
1
+ export const contextMenuClassName = 'compass-context-menu' ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import {
12
12
getContextMenuContent ,
13
13
type EnhancedMouseEvent ,
14
14
} from './context-menu-content' ;
15
+ import { contextMenuClassName } from './consts' ;
15
16
16
17
export const ContextMenuContext = createContext < ContextMenuContextType | null > (
17
18
null
@@ -76,7 +77,16 @@ export function ContextMenuProvider({
76
77
77
78
document . addEventListener ( 'contextmenu' , handleContextMenu ) ;
78
79
window . addEventListener ( 'resize' , handleClosingEvent ) ;
79
- window . addEventListener ( 'scroll' , handleClosingEvent , { capture : true } ) ;
80
+ window . addEventListener (
81
+ 'scroll' ,
82
+ ( e ) => {
83
+ const isCompassContextMenu =
84
+ e . target instanceof HTMLElement &&
85
+ e . target . classList . contains ( contextMenuClassName ) ;
86
+ if ( ! isCompassContextMenu ) handleClosingEvent ( e ) ;
87
+ } ,
88
+ { capture : true }
89
+ ) ;
80
90
81
91
return ( ) => {
82
92
document . removeEventListener ( 'contextmenu' , handleContextMenu ) ;
Original file line number Diff line number Diff line change @@ -5,3 +5,4 @@ export type {
5
5
ContextMenuItemGroup ,
6
6
ContextMenuWrapperProps ,
7
7
} from './types' ;
8
+ export { contextMenuClassName } from './consts' ;
You can’t perform that action at this time.
0 commit comments