From ef2407832202e5451751e26459e6bdcdbd152122 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Sat, 21 May 2022 16:04:06 +0200
Subject: fix: close Ackee tooltip on button click

The tooltip was closing and reopening on click because of a conflict
between the button event and the hook useClickOutside. By checking that
the event target is not the button, the tooltip is now closing as
expected.
---
 src/utils/hooks/use-click-outside.tsx | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

(limited to 'src/utils/hooks/use-click-outside.tsx')

diff --git a/src/utils/hooks/use-click-outside.tsx b/src/utils/hooks/use-click-outside.tsx
index 066c1c2..cead98b 100644
--- a/src/utils/hooks/use-click-outside.tsx
+++ b/src/utils/hooks/use-click-outside.tsx
@@ -6,7 +6,10 @@ import { RefObject, useCallback, useEffect } from 'react';
  * @param el - A React reference to an element.
  * @param callback - A callback function to execute on click outside.
  */
-const useClickOutside = (el: RefObject<HTMLElement>, callback: () => void) => {
+const useClickOutside = (
+  el: RefObject<HTMLElement>,
+  callback: (target: EventTarget) => void
+) => {
   /**
    * Check if an event target is outside an element.
    *
@@ -24,7 +27,7 @@ const useClickOutside = (el: RefObject<HTMLElement>, callback: () => void) => {
 
   const handleEvent = useCallback(
     (e: MouseEvent | FocusEvent) => {
-      if (e.target && isTargetOutside(el, e.target)) callback();
+      if (e.target && isTargetOutside(el, e.target)) callback(e.target);
     },
     [el, callback]
   );
-- 
cgit v1.2.3

