@@ -16,6 +16,8 @@ export interface ContextMenuProps<T extends HTMLElement = HTMLDivElement> {
16
16
menuProps ?: Omit < MenuProps , 'children' > & { children ?: React . ReactNode } ;
17
17
portalProps ?: Omit < PortalProps , 'children' > & { children ?: React . ReactNode } ;
18
18
menuButtonProps ?: MenuButtonProps ;
19
+ stopPropagation ?: boolean ;
20
+ stopImmediatePropagation ?: boolean ;
19
21
}
20
22
21
23
export const ContextMenu = typedMemo ( < T extends HTMLElement = HTMLElement > ( props : ContextMenuProps < T > ) => {
@@ -36,6 +38,12 @@ export const ContextMenu = typedMemo(<T extends HTMLElement = HTMLElement>(props
36
38
// `contains()` requires the arg to be Node. Technically it can be any EventTarget, but it won't cause an error.
37
39
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
38
40
if ( targetRef . current ?. contains ( e . target as Node ) || e . target === targetRef . current ) {
41
+ if ( props . stopImmediatePropagation ) {
42
+ e . stopImmediatePropagation ( ) ;
43
+ }
44
+ if ( props . stopPropagation ) {
45
+ e . stopPropagation ( ) ;
46
+ }
39
47
// clear pending delayed open
40
48
window . clearTimeout ( timeoutRef . current ) ;
41
49
e . preventDefault ( ) ;
@@ -54,7 +62,7 @@ export const ContextMenu = typedMemo(<T extends HTMLElement = HTMLElement>(props
54
62
}
55
63
lastPositionRef . current = [ e . pageX , e . pageY ] ;
56
64
} ,
57
- [ onClose , onOpen ]
65
+ [ onClose , onOpen , props . stopImmediatePropagation , props . stopPropagation ]
58
66
) ;
59
67
60
68
useEffect (
0 commit comments