File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-accessible-dropdown-menu-hook" ,
3
- "version" : " 2.1.1 " ,
3
+ "version" : " 2.1.2 " ,
4
4
"description" : " A simple Hook for creating fully accessible dropdown menus in React" ,
5
5
"main" : " dist/use-dropdown-menu.js" ,
6
6
"types" : " dist/use-dropdown-menu.d.ts" ,
Original file line number Diff line number Diff line change @@ -55,13 +55,13 @@ export default function useDropdownMenu(itemCount: number) {
55
55
56
56
// Handle listening for clicks and auto-hiding the menu
57
57
useEffect ( ( ) => {
58
+ // Ignore if the menu isn't open
59
+ if ( ! isOpen ) {
60
+ return ;
61
+ }
62
+
58
63
// This function is designed to handle every click
59
64
const handleEveryClick = ( event : MouseEvent ) => {
60
- // Ignore if the menu isn't open
61
- if ( ! isOpen ) {
62
- return ;
63
- }
64
-
65
65
// Make this happen asynchronously
66
66
setTimeout ( ( ) => {
67
67
// Type guard
@@ -80,7 +80,10 @@ export default function useDropdownMenu(itemCount: number) {
80
80
} ;
81
81
82
82
// 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 ) ;
84
87
85
88
// Return function to remove listener
86
89
return ( ) => document . removeEventListener ( 'click' , handleEveryClick ) ;
You can’t perform that action at this time.
0 commit comments