From f9c702099d992f6e208263a9bd75bf1d24172404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarz=C4=99bski?= Date: Fri, 18 Oct 2024 12:45:27 +0200 Subject: [PATCH] Hide tooltip without delay for instant tooltips. --- packages/ckeditor5-ui/src/tooltipmanager.ts | 8 ++++++++ .../ckeditor5-ui/tests/tooltip/tooltipmanager.js | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/packages/ckeditor5-ui/src/tooltipmanager.ts b/packages/ckeditor5-ui/src/tooltipmanager.ts index 20e486a28ad..be16e3d5539 100644 --- a/packages/ckeditor5-ui/src/tooltipmanager.ts +++ b/packages/ckeditor5-ui/src/tooltipmanager.ts @@ -366,6 +366,14 @@ export default class TooltipManager extends /* #__PURE__ */ DomEmitterMixin() { if ( isLeavingBalloon || ( descendantWithTooltip && descendantWithTooltip !== relatedDescendantWithTooltip ) ) { this._pinTooltipDebounced.cancel(); + // If the currently visible tooltip is instant, unpin it immediately. + if ( + this._currentElementWithTooltip && this._currentElementWithTooltip.matches( '[data-cke-tooltip-instant]' ) || + descendantWithTooltip && descendantWithTooltip.matches( '[data-cke-tooltip-instant]' ) + ) { + this._unpinTooltip(); + } + this._unpinTooltipDebounced(); } } else { diff --git a/packages/ckeditor5-ui/tests/tooltip/tooltipmanager.js b/packages/ckeditor5-ui/tests/tooltip/tooltipmanager.js index 711a56b74e8..60be18c4f4c 100644 --- a/packages/ckeditor5-ui/tests/tooltip/tooltipmanager.js +++ b/packages/ckeditor5-ui/tests/tooltip/tooltipmanager.js @@ -712,6 +712,19 @@ describe( 'TooltipManager', () => { sinon.assert.calledOnce( unpinSpy ); } ); + it( 'should remove the tooltip immediately if the element has `data-cke-tooltip-instant` attribute', () => { + elements.a.dataset.ckeTooltipInstant = true; + + utils.dispatchMouseEnter( elements.a ); + + sinon.assert.calledOnce( pinSpy ); + + unpinSpy = sinon.spy( tooltipManager.balloonPanelView, 'unpin' ); + utils.dispatchMouseLeave( tooltipManager.balloonPanelView.element, elements.b ); + + sinon.assert.calledOnce( unpinSpy ); + } ); + it( 'should not work if the tooltip is currently pinned and the event target is different than the current element', () => { utils.dispatchMouseEnter( elements.a ); utils.waitForTheTooltipToShow( clock );