Skip to content

Commit

Permalink
fix: tooltip shows on item click (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajbura authored Apr 12, 2023
1 parent 98d70fa commit 270f6de
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ const useTooltip = (position: Position, align: Align, offset: number, delay: num
useEffect(() => {
const trigger = triggerRef.current as HTMLElement;
const tooltip = tooltipRef.current;
let timeoutId: number;
let timeoutId: number | undefined;

const openTooltip = (evt: Event) => {
if (timeoutId) return;
const pos = getRelativeFixedPosition(trigger, position, align, offset);
if (tooltip) {
tooltip.style.top = pos.top;
Expand All @@ -36,11 +37,13 @@ const useTooltip = (position: Position, align: Align, offset: number, delay: num
tooltip.style.left = pos.left;
tooltip.style.transform = pos.transform;
}

if (evt.type === "focus") setOpen(true);
else timeoutId = window.setTimeout(() => setOpen(true), delay);
};
const closeTooltip = () => {
clearTimeout(timeoutId);
timeoutId = undefined;
setOpen(false);
};

Expand Down

0 comments on commit 270f6de

Please sign in to comment.