From 7f5bfc26cf27017266e198dafc96a8569fcaf4a7 Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:37 +0000 Subject: [PATCH 1/7] fix: cancel a pending show on Escape Escape closed the tooltip but left the show timer of `delayShow` running, so a tooltip hovered just before Escape showed after it. Scroll and resize already cancel that timer; Escape now does too. --- src/components/Tooltip/use-tooltip-events.tsx | 1 + .../tooltip-close-and-delay-behavior.spec.js | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/components/Tooltip/use-tooltip-events.tsx b/src/components/Tooltip/use-tooltip-events.tsx index 4f030043..74e1d15e 100644 --- a/src/components/Tooltip/use-tooltip-events.tsx +++ b/src/components/Tooltip/use-tooltip-events.tsx @@ -534,6 +534,7 @@ const useTooltipEvents = ({ return } handleShowRef.current(false) + clearTimeoutRef(tooltipShowDelayTimerRef) } if (actualGlobalCloseEvents.escape) { window.addEventListener('keydown', handleEsc) diff --git a/src/test/tooltip-close-and-delay-behavior.spec.js b/src/test/tooltip-close-and-delay-behavior.spec.js index 37cd5a31..d41f6cb6 100644 --- a/src/test/tooltip-close-and-delay-behavior.spec.js +++ b/src/test/tooltip-close-and-delay-behavior.spec.js @@ -335,6 +335,27 @@ describe('tooltip close and delay behavior', () => { expect(document.getElementById('cancel-show-timer-test')).not.toBeInTheDocument() }) + test('cancels a pending show timer on Escape when configured globally', () => { + render( + <> + Hover Me + + , + ) + + hoverAnchor(screen.getByText('Hover Me')) + advanceTimers(40) + fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' }) + advanceTimers(200) + + expect(document.getElementById('escape-cancels-show-timer-test')).not.toBeInTheDocument() + }) + test('does not close on non-Escape keys', async () => { render( <> From 5181b913b52039f55020f8ddbb6691e65c7dfd54 Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:41 +0000 Subject: [PATCH 2/7] fix: forget the pointer and a pending hide once a clickable tooltip is removed A clickable tooltip records that the pointer is on it, and clears that when the pointer leaves it. When Escape, a scroll or a resize removed the tooltip from under the pointer, or its anchor was removed, no `mouseout` came and the record stayed. The next tooltip from that component then stayed open after the pointer left its anchor. Both removal paths now reset it. Leaving the anchor also starts a `delayHide` timer. When the tooltip was removed before it ran out, it kept running and closed the next tooltip opened with `open()`. Removing the tooltip now clears it. --- src/components/Tooltip/Tooltip.tsx | 7 ++ .../tooltip-close-and-delay-behavior.spec.js | 41 ++++++++- src/test/tooltip-removal.spec.js | 83 +++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 98568d89..84c25ebf 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -208,6 +208,11 @@ const Tooltip = ({ onRemove: () => { setRendered(false) setImperativeOptions(null) + // a tooltip that is not in the DOM is not under the pointer, + // even when it left the DOM without a `mouseout` + hoveringTooltip.current = false + // and a hide that was waiting for the pointer has nothing left to close + clearTimeoutRef(tooltipHideDelayTimerRef) }, }) @@ -394,6 +399,8 @@ const Tooltip = ({ ]) const handleActiveAnchorRemoved = useCallback(() => { + // the tooltip leaves the DOM here too, so it is no longer under the pointer + hoveringTooltip.current = false setRendered(false) handleShow(false) setActiveAnchor(null) diff --git a/src/test/tooltip-close-and-delay-behavior.spec.js b/src/test/tooltip-close-and-delay-behavior.spec.js index d41f6cb6..85337de1 100644 --- a/src/test/tooltip-close-and-delay-behavior.spec.js +++ b/src/test/tooltip-close-and-delay-behavior.spec.js @@ -1,5 +1,5 @@ import React, { useState } from 'react' -import { render, screen, fireEvent } from '@testing-library/react' +import { render, screen, fireEvent, waitFor } from '@testing-library/react' import '@testing-library/jest-dom' import { TooltipController } from '../components/TooltipController' import { @@ -356,6 +356,45 @@ describe('tooltip close and delay behavior', () => { expect(document.getElementById('escape-cancels-show-timer-test')).not.toBeInTheDocument() }) + test('closes a clickable tooltip on leaving its anchor after Escape closed one under the pointer', async () => { + render( + <> + Hover Me + + , + ) + + const anchor = screen.getByText('Hover Me') + hoverAnchor(anchor, 100) + const tooltip = await waitForTooltip('escape-on-tooltip-test') + await waitFor(() => { + expect(tooltip).toHaveClass('react-tooltip__show') + }) + // the pointer moves onto the tooltip, and Escape removes the tooltip from under it + unhoverAnchor(anchor) + fireEvent.mouseOver(tooltip) + fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' }) + advanceTimers(500) + advanceTimers(500) + expect(document.getElementById('escape-on-tooltip-test')).not.toBeInTheDocument() + + hoverAnchor(anchor, 100) + await waitFor(() => { + expect(document.getElementById('escape-on-tooltip-test')).toHaveClass('react-tooltip__show') + }) + unhoverAnchor(anchor) + advanceTimers(500) + // Second advancement needed: the first fires handleShow(false) timeout, + // which creates the missedTransitionTimer during the effect flush + advanceTimers(500) + expect(document.getElementById('escape-on-tooltip-test')).not.toBeInTheDocument() + }) + test('does not close on non-Escape keys', async () => { render( <> diff --git a/src/test/tooltip-removal.spec.js b/src/test/tooltip-removal.spec.js index 166280be..92c20e82 100644 --- a/src/test/tooltip-removal.spec.js +++ b/src/test/tooltip-removal.spec.js @@ -147,6 +147,89 @@ describe('tooltip removal', () => { expect(afterHide).toHaveBeenCalledTimes(1) }) + test.each([ + ['away from the tooltip', false], + ['on the tooltip', true], + ])( + 'drops a hide that was pending when Escape removed a clickable tooltip, pointer %s', + async (_, pointerOnTooltip) => { + const tooltipRef = createRef() + render( + , + ) + + const anchor = screen.getByText('Hover Me') + hoverAnchor(anchor, 100) + await expectTooltipToShow(await waitForTooltip(TOOLTIP_ID)) + // leaving the anchor starts the 1000ms hide + unhoverAnchor(anchor) + if (pointerOnTooltip) { + fireEvent.mouseOver(getTooltip()) + } + fireEvent.keyDown(document, { key: 'Escape', code: 'Escape' }) + advanceTimers(50) + advanceTimers(REMOVAL_MS) + expect(getTooltip()).not.toBeInTheDocument() + + act(() => { + tooltipRef.current.open() + }) + advanceTimers(SHOW_TIMER_MS) + await waitFor(() => { + expect(getTooltip()).toHaveClass('react-tooltip__show') + }) + // the old hide's 1000ms run out + advanceTimers(1000) + advanceTimers(REMOVAL_MS) + expect(getTooltip()).toHaveClass('react-tooltip__show') + }, + ) + + test('closes the next tooltip on leaving its anchor after the anchor of a hovered clickable tooltip is removed', async () => { + const TwoAnchors = () => { + const [hasFirst, setHasFirst] = useState(true) + + return ( + <> + {hasFirst && First} + Second + + + + ) + } + + render() + + const first = screen.getByText('First') + hoverAnchor(first, 100) + await expectTooltipToShow(await waitForTooltip(TOOLTIP_ID)) + // the pointer is on the tooltip when its anchor goes away + unhoverAnchor(first) + fireEvent.mouseOver(getTooltip()) + fireEvent.click(screen.getByText('Remove First')) + mutationObserverController.triggerAll([ + { type: 'childList', removedNodes: [first], addedNodes: [] }, + ]) + advanceTimers(50) + expect(getTooltip()).not.toBeInTheDocument() + + const second = screen.getByText('Second') + hoverAnchor(second, 100) + await waitFor(() => { + expect(getTooltip()).toHaveClass('react-tooltip__show') + }) + unhoverAnchor(second) + advanceTimers(REMOVAL_MS) + advanceTimers(REMOVAL_MS) + expect(getTooltip()).not.toBeInTheDocument() + }) + test('calls afterHide once when the anchor of a showing tooltip is removed', async () => { const afterHide = jest.fn() const AnchorRemovalTest = () => { From 1c65258d8147e4c2a809772123b244dc665158b2 Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:45 +0000 Subject: [PATCH 3/7] fix: wait out the closing transition before removing a closed tooltip The fallback that removes a closed tooltip when no `transitionend` fires was timed by `--rt-transition-show-delay`. With a closing transition longer than the show transition, the tooltip was removed part way through fading out. Refs #1255 --- .../Tooltip/use-tooltip-removal.tsx | 11 ++-- src/test/tooltip-closing-transition.spec.js | 66 +++++++++++++++++++ 2 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 src/test/tooltip-closing-transition.spec.js diff --git a/src/components/Tooltip/use-tooltip-removal.tsx b/src/components/Tooltip/use-tooltip-removal.tsx index aa07a55c..fbd8d727 100644 --- a/src/components/Tooltip/use-tooltip-removal.tsx +++ b/src/components/Tooltip/use-tooltip-removal.tsx @@ -2,15 +2,18 @@ import { useCallback, useEffect, useRef, useState } from 'react' import { cssTimeToMs, useIsomorphicLayoutEffect } from '../../utils' // Shared across all tooltip instances — the CSS variable is on :root and never changes per-instance -let globalTransitionShowDelay: number | null = null +let globalTransitionClosingDelay: number | null = null +// the removal waits as long as the closing transition takes const getMissedTransitionDelay = () => { - if (globalTransitionShowDelay === null) { + if (globalTransitionClosingDelay === null) { const style = getComputedStyle(document.body) - globalTransitionShowDelay = cssTimeToMs(style.getPropertyValue('--rt-transition-show-delay')) + globalTransitionClosingDelay = cssTimeToMs( + style.getPropertyValue('--rt-transition-closing-delay'), + ) } // +25ms just to make sure `onTransitionEnd` (if it gets fired) has time to run - return globalTransitionShowDelay + 25 + return globalTransitionClosingDelay + 25 } /** diff --git a/src/test/tooltip-closing-transition.spec.js b/src/test/tooltip-closing-transition.spec.js new file mode 100644 index 00000000..c4f6deb1 --- /dev/null +++ b/src/test/tooltip-closing-transition.spec.js @@ -0,0 +1,66 @@ +import React from 'react' +import { render, screen, waitFor } from '@testing-library/react' +import '@testing-library/jest-dom' +import { TooltipController } from '../components/TooltipController' +import { + advanceTimers, + flushPendingTimers, + hoverAnchor, + unhoverAnchor, + waitForTooltip, +} from './test-utils' + +jest.mock('@floating-ui/dom', () => { + const originalModule = jest.requireActual('@floating-ui/dom') + return { + ...originalModule, + autoUpdate: jest.fn(() => jest.fn()), + } +}) + +// Its own file: the removal reads the transition lengths once per page, +// so they are set before any tooltip closes. +const TOOLTIP_ID = 'closing-transition-test' +const getTooltip = () => document.getElementById(TOOLTIP_ID) + +describe('tooltip closing transition', () => { + beforeAll(() => { + document.body.style.setProperty('--rt-transition-show-delay', '0.15s') + document.body.style.setProperty('--rt-transition-closing-delay', '0.6s') + }) + + beforeEach(() => { + jest.useFakeTimers() + }) + + afterEach(() => { + flushPendingTimers() + jest.useRealTimers() + }) + + test('keeps a closing tooltip for its closing transition when it is longer than the show transition', async () => { + render( + <> + Hover Me + + , + ) + + const anchor = screen.getByText('Hover Me') + hoverAnchor(anchor, 100) + await waitForTooltip(TOOLTIP_ID) + await waitFor(() => { + expect(getTooltip()).toHaveClass('react-tooltip__show') + }) + + unhoverAnchor(anchor, 20) + expect(getTooltip()).toHaveClass('react-tooltip__closing') + // half way through the 0.6s closing transition + advanceTimers(300) + expect(getTooltip()).toBeInTheDocument() + + // removed after it, even if no `transitionend` fires + advanceTimers(400) + expect(getTooltip()).not.toBeInTheDocument() + }) +}) From 2641153d6ef1c2e641522dede086851b6ac4f0ef Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sat, 14 Nov 2026 22:23:49 +0000 Subject: [PATCH 4/7] fix: end the closing fade on the tooltip's own transition only `transitionend` bubbles, so an opacity transition that ended inside the tooltip's content removed a closing tooltip before its own fade ended. --- .../Tooltip/use-tooltip-removal.tsx | 3 ++- src/test/tooltip-removal.spec.js | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/Tooltip/use-tooltip-removal.tsx b/src/components/Tooltip/use-tooltip-removal.tsx index fbd8d727..0be1b81d 100644 --- a/src/components/Tooltip/use-tooltip-removal.tsx +++ b/src/components/Tooltip/use-tooltip-removal.tsx @@ -89,7 +89,8 @@ const useTooltipRemoval = ({ return useCallback( (event: TransitionEvent) => { - if (!show && event.propertyName === 'opacity') { + // the tooltip's own fade, not a transition inside its content that bubbled up + if (!show && event.target === event.currentTarget && event.propertyName === 'opacity') { setRemovalDue(true) } }, diff --git a/src/test/tooltip-removal.spec.js b/src/test/tooltip-removal.spec.js index 92c20e82..cdbf6f23 100644 --- a/src/test/tooltip-removal.spec.js +++ b/src/test/tooltip-removal.spec.js @@ -147,6 +147,30 @@ describe('tooltip removal', () => { expect(afterHide).toHaveBeenCalledTimes(1) }) + test('keeps a closing tooltip when an opacity transition inside its content ends', async () => { + render( + <> + Hover Me + + Content + + , + ) + + const anchor = screen.getByText('Hover Me') + hoverAnchor(anchor, 100) + const tooltip = await waitForTooltip(TOOLTIP_ID) + await expectTooltipToShow(tooltip) + + unhoverAnchor(anchor, 20) + expect(getTooltip()).toHaveClass('react-tooltip__closing') + fireOpacityTransitionEnd(screen.getByText('Content')) + expect(getTooltip()).toBeInTheDocument() + + fireOpacityTransitionEnd(getTooltip()) + expect(getTooltip()).not.toBeInTheDocument() + }) + test.each([ ['away from the tooltip', false], ['on the tooltip', true], From faa3bb10c6e75005428ac942089787d8e0c930a7 Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:24:42 +0000 Subject: [PATCH 5/7] fix: read the closing transition length on the tooltip The fallback removal read `--rt-transition-closing-delay` from `document.body`, once per page. The fade itself uses the value on the tooltip, so a length set on the tooltip (through `className` or `style`) or on an ancestor of it changed the fade but not the removal: the tooltip was removed part way through fading out. The length is now read on the tooltip each time it closes. Refs #1255 --- src/components/Tooltip/Tooltip.tsx | 1 + .../Tooltip/use-tooltip-removal.tsx | 27 +++++----- src/test/tooltip-closing-transition.spec.js | 51 +++++++++++-------- 3 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/components/Tooltip/Tooltip.tsx b/src/components/Tooltip/Tooltip.tsx index 84c25ebf..c339a50e 100644 --- a/src/components/Tooltip/Tooltip.tsx +++ b/src/components/Tooltip/Tooltip.tsx @@ -214,6 +214,7 @@ const Tooltip = ({ // and a hide that was waiting for the pointer has nothing left to close clearTimeoutRef(tooltipHideDelayTimerRef) }, + tooltipRef, }) useEffect(() => { diff --git a/src/components/Tooltip/use-tooltip-removal.tsx b/src/components/Tooltip/use-tooltip-removal.tsx index 0be1b81d..bad4c1f9 100644 --- a/src/components/Tooltip/use-tooltip-removal.tsx +++ b/src/components/Tooltip/use-tooltip-removal.tsx @@ -1,19 +1,16 @@ import { useCallback, useEffect, useRef, useState } from 'react' +import type { RefObject } from 'react' import { cssTimeToMs, useIsomorphicLayoutEffect } from '../../utils' -// Shared across all tooltip instances — the CSS variable is on :root and never changes per-instance -let globalTransitionClosingDelay: number | null = null - -// the removal waits as long as the closing transition takes -const getMissedTransitionDelay = () => { - if (globalTransitionClosingDelay === null) { - const style = getComputedStyle(document.body) - globalTransitionClosingDelay = cssTimeToMs( - style.getPropertyValue('--rt-transition-closing-delay'), - ) - } +/** + * the removal waits as long as the closing transition takes. + * read on the tooltip, where the transition runs, + * so the variable can be set on the tooltip or on any of its ancestors + */ +const getMissedTransitionDelay = (tooltip: HTMLElement | null) => { + const style = getComputedStyle(tooltip ?? document.body) // +25ms just to make sure `onTransitionEnd` (if it gets fired) has time to run - return globalTransitionClosingDelay + 25 + return cssTimeToMs(style.getPropertyValue('--rt-transition-closing-delay')) + 25 } /** @@ -33,6 +30,7 @@ const useTooltipRemoval = ({ showRequested, afterHide, onRemove, + tooltipRef, }: { rendered: boolean show: boolean @@ -40,6 +38,7 @@ const useTooltipRemoval = ({ showRequested: boolean afterHide?: () => void onRemove: () => void + tooltipRef: RefObject }) => { /** * the timer and the transition end only mark the removal as due. @@ -62,11 +61,11 @@ const useTooltipRemoval = ({ } const timer = setTimeout(() => { setRemovalDue(true) - }, getMissedTransitionDelay()) + }, getMissedTransitionDelay(tooltipRef.current)) return () => { clearTimeout(timer) } - }, [rendered, show, showRequested]) + }, [rendered, show, showRequested, tooltipRef]) /** * `show` and `showRequested` are current here, so this is where a due removal diff --git a/src/test/tooltip-closing-transition.spec.js b/src/test/tooltip-closing-transition.spec.js index c4f6deb1..d233af21 100644 --- a/src/test/tooltip-closing-transition.spec.js +++ b/src/test/tooltip-closing-transition.spec.js @@ -18,17 +18,29 @@ jest.mock('@floating-ui/dom', () => { } }) -// Its own file: the removal reads the transition lengths once per page, -// so they are set before any tooltip closes. const TOOLTIP_ID = 'closing-transition-test' const getTooltip = () => document.getElementById(TOOLTIP_ID) -describe('tooltip closing transition', () => { - beforeAll(() => { - document.body.style.setProperty('--rt-transition-show-delay', '0.15s') - document.body.style.setProperty('--rt-transition-closing-delay', '0.6s') +const showThenClose = async (tooltipProps) => { + render( + <> + Hover Me + + , + ) + + const anchor = screen.getByText('Hover Me') + hoverAnchor(anchor, 100) + await waitForTooltip(TOOLTIP_ID) + await waitFor(() => { + expect(getTooltip()).toHaveClass('react-tooltip__show') }) + unhoverAnchor(anchor, 20) + expect(getTooltip()).toHaveClass('react-tooltip__closing') +} + +describe('tooltip closing transition', () => { beforeEach(() => { jest.useFakeTimers() }) @@ -39,22 +51,10 @@ describe('tooltip closing transition', () => { }) test('keeps a closing tooltip for its closing transition when it is longer than the show transition', async () => { - render( - <> - Hover Me - - , - ) - - const anchor = screen.getByText('Hover Me') - hoverAnchor(anchor, 100) - await waitForTooltip(TOOLTIP_ID) - await waitFor(() => { - expect(getTooltip()).toHaveClass('react-tooltip__show') + await showThenClose({ + style: { '--rt-transition-show-delay': '0.15s', '--rt-transition-closing-delay': '0.6s' }, }) - unhoverAnchor(anchor, 20) - expect(getTooltip()).toHaveClass('react-tooltip__closing') // half way through the 0.6s closing transition advanceTimers(300) expect(getTooltip()).toBeInTheDocument() @@ -63,4 +63,15 @@ describe('tooltip closing transition', () => { advanceTimers(400) expect(getTooltip()).not.toBeInTheDocument() }) + + test('keeps a closing tooltip for its closing transition when the length is set on the tooltip', async () => { + // nothing on body: the length is read where the transition runs + await showThenClose({ style: { '--rt-transition-closing-delay': '0.6s' } }) + + advanceTimers(300) + expect(getTooltip()).toBeInTheDocument() + + advanceTimers(400) + expect(getTooltip()).not.toBeInTheDocument() + }) }) From 50a1643b24283492035f6ca70fb56e007b4f74b0 Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Sun, 15 Nov 2026 19:25:30 +0000 Subject: [PATCH 6/7] fix: let a :root rule override the default CSS variables The docs say to change the opacity or the transition lengths by setting the `--rt-*` variables on `:root`. The defaults are on `:root` too, in the styles the library injects after the app's own, so at the same specificity the defaults won and the app's `:root` rule did nothing. The defaults are now in `:where(:root)`, which has no specificity. --- src/tokens.css | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tokens.css b/src/tokens.css index 6220a6e5..f5356baf 100644 --- a/src/tokens.css +++ b/src/tokens.css @@ -1,4 +1,8 @@ -:root { +/** + * The defaults have no specificity, so an app's own :root rule (outside a cascade layer) + * overrides them wherever it comes in the page. The injected styles can come after the app's. + */ +:where(:root) { --rt-color-white: #fff; --rt-color-dark: #222; --rt-color-success: #8dc572; From e5505239976832e460a3a2d47baafa6073d76c2f Mon Sep 17 00:00:00 2001 From: Goga Koreli <12997449+gogakoreli@users.noreply.github.com> Date: Mon, 16 Nov 2026 18:25:37 +0000 Subject: [PATCH 7/7] fix: time the fallback removal by a calc() closing delay too A custom property keeps an expression such as `calc(0.3s + 0.3s)` as written, so `cssTimeToMs` read the closing delay as 0 and the tooltip was removed 25 ms into a 600 ms fade. The closing transition that uses the variable has it resolved, so its duration is read when the variable is not a plain time. --- src/components/Tooltip/use-tooltip-removal.tsx | 7 ++++++- src/test/tooltip-closing-transition.spec.js | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/Tooltip/use-tooltip-removal.tsx b/src/components/Tooltip/use-tooltip-removal.tsx index bad4c1f9..5ec3ffd5 100644 --- a/src/components/Tooltip/use-tooltip-removal.tsx +++ b/src/components/Tooltip/use-tooltip-removal.tsx @@ -9,8 +9,13 @@ import { cssTimeToMs, useIsomorphicLayoutEffect } from '../../utils' */ const getMissedTransitionDelay = (tooltip: HTMLElement | null) => { const style = getComputedStyle(tooltip ?? document.body) + // a custom property keeps an expression such as `calc()` as written, which reads as 0 here. + // the closing transition that uses it has it resolved + const delay = + cssTimeToMs(style.getPropertyValue('--rt-transition-closing-delay').trim()) || + cssTimeToMs(style.transitionDuration.split(',')[0].trim()) // +25ms just to make sure `onTransitionEnd` (if it gets fired) has time to run - return cssTimeToMs(style.getPropertyValue('--rt-transition-closing-delay')) + 25 + return delay + 25 } /** diff --git a/src/test/tooltip-closing-transition.spec.js b/src/test/tooltip-closing-transition.spec.js index d233af21..085c9193 100644 --- a/src/test/tooltip-closing-transition.spec.js +++ b/src/test/tooltip-closing-transition.spec.js @@ -74,4 +74,18 @@ describe('tooltip closing transition', () => { advanceTimers(400) expect(getTooltip()).not.toBeInTheDocument() }) + + test('keeps a closing tooltip for its closing transition when the length is a calc() expression', async () => { + // a custom property keeps `calc()` as written. jsdom does not apply the closing class's + // stylesheet, so the resolved length of the closing transition is set directly + await showThenClose({ + style: { '--rt-transition-closing-delay': 'calc(0.3s + 0.3s)', transitionDuration: '0.6s' }, + }) + + advanceTimers(300) + expect(getTooltip()).toBeInTheDocument() + + advanceTimers(400) + expect(getTooltip()).not.toBeInTheDocument() + }) })