Skip to content

Commit 7c9a583

Browse files
committed
Add event listener asynchronously to fix portal bug in React v17
facebook/react#20074
1 parent 69a25ca commit 7c9a583

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/use-dropdown-menu.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)