From 5c0879750055330f1a4dc45ab26954acedb12d9f Mon Sep 17 00:00:00 2001 From: mertsincan Date: Fri, 2 Oct 2020 13:23:19 +0300 Subject: [PATCH] Fixed #523 - Tooltip doesn't close in scrollable containers --- src/components/tooltip/Tooltip.js | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/components/tooltip/Tooltip.js b/src/components/tooltip/Tooltip.js index a861183af..36d609a64 100755 --- a/src/components/tooltip/Tooltip.js +++ b/src/components/tooltip/Tooltip.js @@ -1,5 +1,6 @@ import UniqueComponentId from '../utils/UniqueComponentId'; import DomHandler from '../utils/DomHandler'; +import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler'; function bindEvents(el) { const modifiers = el.$_ptooltipModifiers; @@ -27,6 +28,22 @@ function unbindEvents(el) { } } +function bindScrollListener(el) { + if (!el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler = new ConnectedOverlayScrollHandler(el, function() { + hide(el); + }); + } + + el.$_ptooltipScrollHandler.bindScrollListener(); +} + +function unbindScrollListener(el) { + if (el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler.unbindScrollListener(); + } +} + function onMouseEnter(event) { show(event.currentTarget); } @@ -61,10 +78,13 @@ function show(el) { hide(el); this.removeEventListener('resize', onWindowResize); }); + + bindScrollListener(el); } function hide(el) { remove(el); + unbindScrollListener(el); } function getTooltipElement(el) { @@ -225,6 +245,11 @@ const Tooltip = { unmounted(el) { remove(el); unbindEvents(el); + + if (el.$_ptooltipScrollHandler) { + el.$_ptooltipScrollHandler.destroy(); + el.$_ptooltipScrollHandler = null; + } }, updated(el, options) { el.$_ptooltipModifiers = options.modifiers; @@ -232,4 +257,4 @@ const Tooltip = { } }; -export default Tooltip; \ No newline at end of file +export default Tooltip;