diff --git a/packages/core/package.json b/packages/core/package.json index d9939826..cc610dad 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -24,9 +24,7 @@ }, "license": "MIT", "author": "jer3m01 ", - "contributors": [ - "Fabien Marie-Louise " - ], + "contributors": ["Fabien Marie-Louise "], "sideEffects": false, "type": "module", "exports": { @@ -47,18 +45,11 @@ "types": "dist/index.d.ts", "typesVersions": { "*": { - "*": [ - "./dist/*/index.d.ts", - "./dist/index.d.ts" - ] + "*": ["./dist/*/index.d.ts", "./dist/index.d.ts"] } }, "source": "src/index.tsx", - "files": [ - "dist", - "src", - "NOTICE.txt" - ], + "files": ["dist", "src", "NOTICE.txt"], "scripts": { "build": "pnpm build:cp && pnpm build:tsup", "build:cp": "cp ../../NOTICE.txt .", diff --git a/packages/core/src/tooltip/tooltip-root.tsx b/packages/core/src/tooltip/tooltip-root.tsx index 5da618ae..dc2d6c5f 100644 --- a/packages/core/src/tooltip/tooltip-root.tsx +++ b/packages/core/src/tooltip/tooltip-root.tsx @@ -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< @@ -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; @@ -116,6 +120,7 @@ export function TooltipRoot(props: TooltipRootProps) { id: defaultId, openDelay: 700, closeDelay: 300, + skipDelayDuration: 300, }, props, ); @@ -129,6 +134,7 @@ export function TooltipRoot(props: TooltipRootProps) { "triggerOnFocusOnly", "openDelay", "closeDelay", + "skipDelayDuration", "ignoreSafeArea", "forceMount", ]); @@ -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); @@ -214,6 +227,9 @@ export function TooltipRoot(props: TooltipRootProps) { window.clearTimeout(globalCoolDownTimeout); globalCoolDownTimeout = undefined; + + window.clearTimeout(globalSkipDelayTimeout); + globalSkipDelayTimeout = undefined; }; const warmupTooltip = () => { @@ -244,7 +260,8 @@ export function TooltipRoot(props: TooltipRootProps) { !immediate && local.openDelay && local.openDelay > 0 && - !closeTimeoutId + !closeTimeoutId && + !globalSkipDelayTimeout ) { warmupTooltip(); } else {