Skip to content

Commit d2b9045

Browse files
committed
Only add event listener if menu is open
1 parent 7c9a583 commit d2b9045

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/use-dropdown-menu.ts

Lines changed: 5 additions & 5 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

0 commit comments

Comments
 (0)