Skip to content

Commit d12d128

Browse files
committed
Merge branch 'master' into catch-up-to-speed
2 parents 3c95744 + 284c3b0 commit d12d128

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/use-dropdown-menu.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff 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);

0 commit comments

Comments
 (0)