summaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-05-21 16:04:06 +0200
committerArmand Philippot <git@armandphilippot.com>2022-05-21 19:24:48 +0200
commitef2407832202e5451751e26459e6bdcdbd152122 (patch)
treed7fe063755168619cba78425cb7794807d954d84 /src/utils
parente305cbbdbc49af575e25957f6ab72ccf944339ec (diff)
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.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/hooks/use-click-outside.tsx7
1 files changed, 5 insertions, 2 deletions
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]
);