From 1e4b48aa075e6131a7244cd4726ddb5ba75fcecf Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Wed, 1 Nov 2023 16:10:31 +0100 Subject: 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 --- src/components/molecules/modals/tooltip/tooltip.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/components') 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 = ({ const tooltipClass = `${styles.tooltip} ${styles[directionModifier]} ${styles[visibilityModifier]} ${className}`; const btnRef = useRef(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(); } }; -- cgit v1.2.3