-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: 🐛 fix grouping selector not closing on outside click
- Loading branch information
1 parent
67d83a0
commit 1297869
Showing
5 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/workspace-fusion/src/lib/hooks/useGardenPopoverOutsideClick.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { MutableRefObject, useEffect } from 'react'; | ||
|
||
export const useOutsideClick = ( | ||
handler: (e: MouseEvent, el: HTMLElement) => void, | ||
...refs: MutableRefObject<HTMLElement | null>[] | ||
) => { | ||
const onOutsideClick = (e: MouseEvent) => { | ||
/** Eds input LI is removed from dom before callback runs */ | ||
if (!document.contains(e.target as Node)) { | ||
return; | ||
} | ||
|
||
// updated this to use the passed componentRef | ||
const inMain = refs.some((s) => s.current?.contains(e.target as HTMLElement)); | ||
const isOutside = !inMain; | ||
if (isOutside) { | ||
handler(e, e.target as HTMLElement); | ||
} | ||
}; | ||
useEffect(() => { | ||
document.addEventListener('click', onOutsideClick); | ||
return () => { | ||
document.removeEventListener('click', onOutsideClick); | ||
}; | ||
}, [refs]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters