Skip to content

Commit

Permalink
Fixed #1607 - Tooltip doesn't close in scrollable containers
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Oct 2, 2020
1 parent 6e11ccf commit c332bb8
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/components/tooltip/Tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import DomHandler from '../utils/DomHandler';
import ConnectedOverlayScrollHandler from '../utils/ConnectedOverlayScrollHandler';

export function tip(props) {
let appendTo = props.appendTo || document.body;
Expand Down Expand Up @@ -158,6 +159,7 @@ export class Tooltip extends Component {
});

this.bindDocumentResizeListener();
this.bindScrollListener();
});
}
}
Expand All @@ -177,7 +179,9 @@ export class Tooltip extends Component {
}

this.unbindDocumentResizeListener();
this.unbindScrollListener();
this.currentTarget = null;
this.scrollHandler = null;
this.sendCallback(this.props.onHide, { originalEvent: e, target: this.currentTarget });
});
});
Expand Down Expand Up @@ -250,6 +254,24 @@ export class Tooltip extends Component {
}
}

bindScrollListener() {
if (!this.scrollHandler) {
this.scrollHandler = new ConnectedOverlayScrollHandler(this.currentTarget, (e) => {
if (this.state.visible) {
this.hide(e);
}
});
}

this.scrollHandler.bindScrollListener();
}

unbindScrollListener() {
if (this.scrollHandler) {
this.scrollHandler.unbindScrollListener();
}
}

bindTargetEvent(target) {
if (target) {
const { showEvent, hideEvent } = this.getEvents();
Expand Down Expand Up @@ -337,6 +359,11 @@ export class Tooltip extends Component {
this.clearTimeouts();
this.unbindDocumentResizeListener();
this.unbindTargetEvent();

if (this.scrollHandler) {
this.scrollHandler.destroy();
this.scrollHandler = null;
}
}

renderElement() {
Expand Down

0 comments on commit c332bb8

Please sign in to comment.