diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-01 16:10:31 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 1e4b48aa075e6131a7244cd4726ddb5ba75fcecf (patch) | |
| tree | ba0377440419f6690f079c1fc9de5915db805a38 /src/components | |
| parent | 2844a2bd71dcf1eb17a53992c10129b7496332e0 (diff) | |
refactor(hooks): rewrite useOnClickOutside hook
* remove `useCapture` parameter (it does not make sense to use bubbling
here)
* return a MutableRefObject instead of a RefObject to be able to test
the hook
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/molecules/modals/tooltip/tooltip.tsx | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/components/molecules/modals/tooltip/tooltip.tsx b/src/components/molecules/modals/tooltip/tooltip.tsx index b3a3f5a..525900d 100644 --- a/src/components/molecules/modals/tooltip/tooltip.tsx +++ b/src/components/molecules/modals/tooltip/tooltip.tsx @@ -61,10 +61,12 @@ export const Tooltip: FC<TooltipProps> = ({ const tooltipClass = `${styles.tooltip} ${styles[directionModifier]} ${styles[visibilityModifier]} ${className}`; const btnRef = useRef<HTMLButtonElement>(null); - const closeModal = (target: Node) => { - if (!onClickOutside) return; - - if (btnRef.current && !btnRef.current.contains(target)) { + const closeModal = ({ target }: MouseEvent | FocusEvent) => { + if ( + onClickOutside && + btnRef.current && + !btnRef.current.contains(target as Node) + ) { onClickOutside(); } }; |
