Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when tooltip anchor is removed from document without being unmounted #1119

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

- Added TypeScript definition for `findTestSubject` test util ([#1106](https://github.com/elastic/eui/pull/1106))

**Bug fixes**

- Fixed bug where `EuiToolTip` content wasn't removed if its anchor is removed from the document ([#1119](https://github.com/elastic/eui/pull/1119))

## [`3.6.0`](https://github.com/elastic/eui/tree/v3.6.0)

- Added `EuiCopy` ([#1112](https://github.com/elastic/eui/pull/1112))
Expand Down
21 changes: 21 additions & 0 deletions src/components/tool_tip/tool_tip.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ export class EuiToolTip extends Component {
};
}

componentDidUpdate(prevProps, prevState) {
if (prevState.visible === false && this.state.visible === true) {
requestAnimationFrame(this.testAnchor);
}
}

testAnchor = () => {
// when the tooltip is visible, this checks if the anchor is still part of document
// this fixes when the react root is removed from the dom without unmounting
// https://github.com/elastic/eui/issues/1105
if (document.contains(this.anchor) === false) {
// the anchor is no longer part of `document`
this.hideToolTip();
} else {
if (this.state.visible) {
// if still visible, keep checking
requestAnimationFrame(this.testAnchor);
}
}
}

setPopoverRef = ref => {
this.popover = ref;

Expand Down