Skip to content

Commit

Permalink
fix(FloatingTip): fixes delay timeouts for hover + mouseover
Browse files Browse the repository at this point in the history
Fixes FloatingTips weirdness - basically cancels the open call for Tooltips if the user doesn't hover or focus for the delay timeout
  • Loading branch information
dreamwasp authored Oct 4, 2024
1 parent 70227c5 commit b644cac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions packages/gamut/src/Tip/shared/FloatingTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,31 @@ export const FloatingTip: React.FC<TipWrapperProps> = ({
const popoverAlignments = getPopoverAlignment({ alignment, type });
const dims = getAlignmentWidths({ avatar, alignment, type });

let hoverDelay: NodeJS.Timeout | undefined;
let focusDelay: NodeJS.Timeout | undefined;

const handleShowHideAction = ({ type }: FocusOrMouseEvent) => {
if (type === 'focus' && !isOpen) {
runWithDelay(() => {
focusDelay = runWithDelay(() => {
setIsOpen(true);
setIsFocused(true);
});
}
if (type === 'blur' && isOpen) {
setIsOpen(false);
setIsFocused(false);
if (type === 'blur') {
if (focusDelay) clearTimeout(focusDelay);
if (isOpen) {
setIsOpen(false);
setIsFocused(false);
}
}
if (type === 'mouseenter' && !isOpen) {
runWithDelay(() => setIsOpen(true));
hoverDelay = runWithDelay(() => setIsOpen(true));
}
if (type === 'mouseleave' && isOpen && !isFocused) {
setIsOpen(false);
if (type === 'mouseleave') {
if (hoverDelay) clearTimeout(hoverDelay);
if (isOpen && !isFocused) {
setIsOpen(false);
}
}
};

Expand Down
2 changes: 1 addition & 1 deletion packages/gamut/src/Tip/shared/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
import { TipPlacementComponentProps, TipWrapperProps } from './types';

export const runWithDelay = (func: () => void) => {
setTimeout(func, timingValues?.base);
return setTimeout(func, timingValues?.base);
};

export const getAlignmentWidths = ({
Expand Down

0 comments on commit b644cac

Please sign in to comment.