Skip to content

Commit

Permalink
feat(tooltip): add skipDelayDuration prop (#467)
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-rb authored Aug 25, 2024
1 parent ea7e7f9 commit cfb0a01
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/core/src/tooltip/tooltip-root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ let tooltipsCounter = 0;
let globalWarmedUp = false;
let globalWarmUpTimeout: number | undefined;
let globalCoolDownTimeout: number | undefined;
let globalSkipDelayTimeout: number | undefined;

export interface TooltipRootOptions
extends Omit<
Expand Down Expand Up @@ -82,6 +83,9 @@ export interface TooltipRootOptions
/** The duration from when the mouse leaves the trigger or content until the tooltip closes. */
closeDelay?: number;

/** The duration from when the mouse leaves the trigger or content and moves to another tooltip trigger or content */
skipDelayDuration?: number;

/** Whether to close the tooltip even if the user cursor is inside the safe area between the trigger and tooltip. */
ignoreSafeArea?: boolean;

Expand Down Expand Up @@ -116,6 +120,7 @@ export function TooltipRoot(props: TooltipRootProps) {
id: defaultId,
openDelay: 700,
closeDelay: 300,
skipDelayDuration: 300,
},
props,
);
Expand All @@ -129,6 +134,7 @@ export function TooltipRoot(props: TooltipRootProps) {
"triggerOnFocusOnly",
"openDelay",
"closeDelay",
"skipDelayDuration",
"ignoreSafeArea",
"forceMount",
]);
Expand Down Expand Up @@ -186,6 +192,13 @@ export function TooltipRoot(props: TooltipRootProps) {
window.clearTimeout(globalWarmUpTimeout);
globalWarmUpTimeout = undefined;

if (local.skipDelayDuration && local.skipDelayDuration >= 0) {
globalSkipDelayTimeout = window.setTimeout(() => {
window.clearTimeout(globalSkipDelayTimeout);
globalSkipDelayTimeout = undefined;
}, local.skipDelayDuration);
}

if (globalWarmedUp) {
window.clearTimeout(globalCoolDownTimeout);

Expand Down Expand Up @@ -214,6 +227,9 @@ export function TooltipRoot(props: TooltipRootProps) {

window.clearTimeout(globalCoolDownTimeout);
globalCoolDownTimeout = undefined;

window.clearTimeout(globalSkipDelayTimeout);
globalSkipDelayTimeout = undefined;
};

const warmupTooltip = () => {
Expand Down Expand Up @@ -244,7 +260,8 @@ export function TooltipRoot(props: TooltipRootProps) {
!immediate &&
local.openDelay &&
local.openDelay > 0 &&
!closeTimeoutId
!closeTimeoutId &&
!globalSkipDelayTimeout
) {
warmupTooltip();
} else {
Expand Down

0 comments on commit cfb0a01

Please sign in to comment.