Fixed #523 - Tooltip doesn't close in scrollable containers

pull/525/head
mertsincan 2020-10-02 13:23:19 +03:00
parent 50c312d0e9
commit 5c08797500
1 changed files with 26 additions and 1 deletions

View File

@ -1,5 +1,6 @@
import UniqueComponentId from '../utils/UniqueComponentId'; import UniqueComponentId from '../utils/UniqueComponentId';
import DomHandler from '../utils/DomHandler'; import DomHandler from '../utils/DomHandler';
import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler';
function bindEvents(el) { function bindEvents(el) {
const modifiers = el.$_ptooltipModifiers; 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) { function onMouseEnter(event) {
show(event.currentTarget); show(event.currentTarget);
} }
@ -61,10 +78,13 @@ function show(el) {
hide(el); hide(el);
this.removeEventListener('resize', onWindowResize); this.removeEventListener('resize', onWindowResize);
}); });
bindScrollListener(el);
} }
function hide(el) { function hide(el) {
remove(el); remove(el);
unbindScrollListener(el);
} }
function getTooltipElement(el) { function getTooltipElement(el) {
@ -225,6 +245,11 @@ const Tooltip = {
unmounted(el) { unmounted(el) {
remove(el); remove(el);
unbindEvents(el); unbindEvents(el);
if (el.$_ptooltipScrollHandler) {
el.$_ptooltipScrollHandler.destroy();
el.$_ptooltipScrollHandler = null;
}
}, },
updated(el, options) { updated(el, options) {
el.$_ptooltipModifiers = options.modifiers; el.$_ptooltipModifiers = options.modifiers;
@ -232,4 +257,4 @@ const Tooltip = {
} }
}; };
export default Tooltip; export default Tooltip;