File tree Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Expand file tree Collapse file tree 2 files changed +26
-11
lines changed Original file line number Diff line number Diff line change @@ -117,6 +117,25 @@ describe('OverflowMenu', () => {
117117 expect ( onClose ) . toHaveBeenCalled ( ) ;
118118 } ) ;
119119
120+ it ( 'should call onClose only once when menu is closed' , async ( ) => {
121+ const onClose = jest . fn ( ) ;
122+ render (
123+ < OverflowMenu
124+ aria-label = "Overflow menu"
125+ className = "extra-class"
126+ onClose = { onClose } >
127+ < OverflowMenuItem className = "test-child" itemText = "one" />
128+ < OverflowMenuItem className = "test-child" itemText = "two" />
129+ </ OverflowMenu >
130+ ) ;
131+
132+ await userEvent . click ( screen . getByRole ( 'button' ) ) ;
133+ await userEvent . click ( screen . getByText ( 'one' ) ) ;
134+ await waitFor ( ( ) => {
135+ expect ( onClose ) . toHaveBeenCalledTimes ( 1 ) ;
136+ } ) ;
137+ } ) ;
138+
120139 it ( 'should call onFocus' , async ( ) => {
121140 const onFocus = jest . fn ( ) ;
122141 render (
Original file line number Diff line number Diff line change @@ -342,17 +342,13 @@ export const OverflowMenu = forwardRef<HTMLButtonElement, OverflowMenuProps>(
342342 }
343343 } , [ ] ) ;
344344
345- const closeMenu = useCallback (
346- ( onCloseMenu ?: ( ) => void ) => {
347- setOpen ( false ) ;
348- // Optional callback to be executed after the state as been set to close
349- if ( onCloseMenu ) {
350- onCloseMenu ( ) ;
351- }
352- onClose ( ) ;
353- } ,
354- [ onClose ]
355- ) ;
345+ const closeMenu = useCallback ( ( onCloseMenu ?: ( ) => void ) => {
346+ setOpen ( false ) ;
347+ // Optional callback to be executed after the state as been set to close
348+ if ( onCloseMenu ) {
349+ onCloseMenu ( ) ;
350+ }
351+ } , [ ] ) ;
356352
357353 const closeMenuAndFocus = useCallback ( ( ) => {
358354 const wasClicked = click ;
You can’t perform that action at this time.
0 commit comments