@@ -4,8 +4,10 @@ import cx from 'clsx';
44import MenuItem from './MenuItem' ;
55import Separator from './Separator' ;
66import SubMenu from './SubMenu' ;
7+
78import { cloneChildren , getCursorPosition , validateMenuPosition } from '../utils' ;
89import { HIDE_ON_EVENTS } from '../constants' ;
10+ import ContextProvider from '../context' ;
911import { Position } from '../types' ;
1012
1113export interface ContextMenuProps extends HTMLAttributes < HTMLDivElement > {
@@ -58,16 +60,14 @@ const ContextMenu = ({
5860 } ;
5961
6062 const hide = ( ) => {
61- const position = { x : 0 , y : 0 } ;
62-
63- if ( animateExit ) setState ( ( prev ) => ( { ...prev , position, leaving : true } ) ) ;
64- else setState ( ( prev ) => ( { ...prev , position, active : false } ) ) ;
63+ if ( animateExit ) setState ( ( prev ) => ( { ...prev , leaving : true } ) ) ;
64+ else setState ( ( prev ) => ( { ...prev , active : false } ) ) ;
6565 } ;
6666
6767 const handleAnimationEnd = ( ) => {
6868 const { leaving, active } = state ;
6969
70- if ( leaving && active ) setState ( ( prev ) => ( { ... prev , active : false , leaving : false } ) ) ;
70+ if ( leaving && active ) setState ( ( ) => ( { position : { x : 0 , y : 0 } , active : false , leaving : false } ) ) ;
7171 } ;
7272
7373 useEffect ( ( ) => {
@@ -109,7 +109,7 @@ const ContextMenu = ({
109109 onClick = { ( event ) => event . stopPropagation ( ) }
110110 tabIndex = { - 1 }
111111 >
112- { cloneChildren ( children , { hide } ) }
112+ < ContextProvider hide = { hide } > { cloneChildren ( children ) } </ ContextProvider >
113113 </ div >
114114 ) ;
115115} ;
0 commit comments