From f120a4fa1f18de9cd8c7d513ef20d5e0a3993ebe Mon Sep 17 00:00:00 2001 From: dev-rb Date: Sun, 18 Aug 2024 13:38:32 -0400 Subject: [PATCH 1/4] feat(tooltip):add skipDelayDuration prop --- packages/core/dev/App.tsx | 34 +++++++++++++++++++++- packages/core/src/tooltip/tooltip-root.tsx | 17 ++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/packages/core/dev/App.tsx b/packages/core/dev/App.tsx index bf49446a4..db6136ed5 100644 --- a/packages/core/dev/App.tsx +++ b/packages/core/dev/App.tsx @@ -1,5 +1,37 @@ +import { Tooltip } from "../src"; + export default function App() { return ( - <> +
+ + 1 + Button 1 + + + 2 + Button 2 + + + 3 + Button 3 + + + 4 + Button 4 + + + 5 + Button 5 + + + 6 + Button 6 + +
); } diff --git a/packages/core/src/tooltip/tooltip-root.tsx b/packages/core/src/tooltip/tooltip-root.tsx index 5da618aed..5400d8aa3 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; @@ -129,6 +133,7 @@ export function TooltipRoot(props: TooltipRootProps) { "triggerOnFocusOnly", "openDelay", "closeDelay", + "skipDelayDuration", "ignoreSafeArea", "forceMount", ]); @@ -186,6 +191,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 +226,9 @@ export function TooltipRoot(props: TooltipRootProps) { window.clearTimeout(globalCoolDownTimeout); globalCoolDownTimeout = undefined; + + window.clearTimeout(globalSkipDelayTimeout); + globalSkipDelayTimeout = undefined; }; const warmupTooltip = () => { @@ -244,7 +259,7 @@ export function TooltipRoot(props: TooltipRootProps) { !immediate && local.openDelay && local.openDelay > 0 && - !closeTimeoutId + !closeTimeoutId && !globalSkipDelayTimeout ) { warmupTooltip(); } else { From 3569924cb781c0e3042b5e6167361afd9f877f68 Mon Sep 17 00:00:00 2001 From: dev-rb Date: Sun, 18 Aug 2024 13:43:48 -0400 Subject: [PATCH 2/4] style: format --- packages/core/package.json | 15 +++------------ packages/core/src/tooltip/tooltip-root.tsx | 11 ++++++----- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index d99398266..cc610dadc 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 5400d8aa3..3afb303d8 100644 --- a/packages/core/src/tooltip/tooltip-root.tsx +++ b/packages/core/src/tooltip/tooltip-root.tsx @@ -191,11 +191,11 @@ export function TooltipRoot(props: TooltipRootProps) { window.clearTimeout(globalWarmUpTimeout); globalWarmUpTimeout = undefined; - if(local.skipDelayDuration && local.skipDelayDuration >= 0){ + if (local.skipDelayDuration && local.skipDelayDuration >= 0) { globalSkipDelayTimeout = window.setTimeout(() => { - window.clearTimeout(globalSkipDelayTimeout) - globalSkipDelayTimeout = undefined - }, local.skipDelayDuration) + window.clearTimeout(globalSkipDelayTimeout); + globalSkipDelayTimeout = undefined; + }, local.skipDelayDuration); } if (globalWarmedUp) { @@ -259,7 +259,8 @@ export function TooltipRoot(props: TooltipRootProps) { !immediate && local.openDelay && local.openDelay > 0 && - !closeTimeoutId && !globalSkipDelayTimeout + !closeTimeoutId && + !globalSkipDelayTimeout ) { warmupTooltip(); } else { From 1a5811fdc91b2e5bc3c00ac8757e73cef78ea867 Mon Sep 17 00:00:00 2001 From: dev-rb Date: Sun, 18 Aug 2024 13:45:50 -0400 Subject: [PATCH 3/4] fix: add default value for skipDelayDuration --- packages/core/src/tooltip/tooltip-root.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/tooltip/tooltip-root.tsx b/packages/core/src/tooltip/tooltip-root.tsx index 3afb303d8..dc2d6c5fb 100644 --- a/packages/core/src/tooltip/tooltip-root.tsx +++ b/packages/core/src/tooltip/tooltip-root.tsx @@ -120,6 +120,7 @@ export function TooltipRoot(props: TooltipRootProps) { id: defaultId, openDelay: 700, closeDelay: 300, + skipDelayDuration: 300, }, props, ); From 0474090d56f39a65db6291ec0112f2f056f4efea Mon Sep 17 00:00:00 2001 From: dev-rb Date: Sat, 24 Aug 2024 12:46:26 -0400 Subject: [PATCH 4/4] chore: remove dev file --- packages/core/dev/App.tsx | 34 +--------------------------------- 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/packages/core/dev/App.tsx b/packages/core/dev/App.tsx index db6136ed5..bf49446a4 100644 --- a/packages/core/dev/App.tsx +++ b/packages/core/dev/App.tsx @@ -1,37 +1,5 @@ -import { Tooltip } from "../src"; - export default function App() { return ( -
- - 1 - Button 1 - - - 2 - Button 2 - - - 3 - Button 3 - - - 4 - Button 4 - - - 5 - Button 5 - - - 6 - Button 6 - -
+ <> ); }