Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FloatingTip): fixes delay timeouts for hover + mouseover #2943

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading