File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -55,13 +55,13 @@ export default function useDropdownMenu(itemCount: number) {
5555
5656 // Handle listening for clicks and auto-hiding the menu
5757 useEffect ( ( ) => {
58+ // Ignore if the menu isn't open
59+ if ( ! isOpen ) {
60+ return ;
61+ }
62+
5863 // This function is designed to handle every click
5964 const handleEveryClick = ( event : MouseEvent ) => {
60- // Ignore if the menu isn't open
61- if ( ! isOpen ) {
62- return ;
63- }
64-
6565 // Make this happen asynchronously
6666 setTimeout ( ( ) => {
6767 // Type guard
@@ -80,7 +80,10 @@ export default function useDropdownMenu(itemCount: number) {
8080 } ;
8181
8282 // Add listener
83- document . addEventListener ( 'click' , handleEveryClick ) ;
83+ // -> Force it to be async to fix: https://github.com/facebook/react/issues/20074
84+ setTimeout ( ( ) => {
85+ document . addEventListener ( 'click' , handleEveryClick ) ;
86+ } , 1 ) ;
8487
8588 // Return function to remove listener
8689 return ( ) => document . removeEventListener ( 'click' , handleEveryClick ) ;
You can’t perform that action at this time.
0 commit comments