Usage with react-virtualized
Has anyone had any luck getting the position correct using a react-tooltip within a react-virtualized list?
It seems like the react-tooltip's can't get their position right and they get confused about their position within the virtualized list.
Turns putting react-tooltip's within a react-virtualized List is really complicated. Best to bind react-tooltip's from outside of virtualized components.
@sedouard What did you end up doing to fix this?
You have to place the tooltips outside of the virtualized area and have them be not virtualized. The way absolute positioning works within the virtualized area is pretty tough because you need to know how many items are rendered above an arbitrary point in the virtualized list.
So we build the tooltips first:
const tooltips = projects.map(({ id }) => <ReactTooltip id={id} key={id} effect="solid" />);
And then place them outside of the virtualized list:
render () {
<List
onScroll={
_.throttle(() => {
ReactTooltip.rebuild();
ReactTooltip.hide();
}, 200)
}>
</List>
{tooltips}
}
@sedouard I'm having the same issue, in my case it's Autosizer and Table. Do you have another example or a more simple example/ approach to this? In my case only IE11 does it correctly, FF and Chrome do not.
For anyone still looking for a solution with AutoSizer + Table, I got this working performatively.
I found that rendering a Tooltip for each row as recommended had a dramatic effect on performance with more than a small number of rows, so I wanted to get it working by only rendering one. The important part is just calling the tooltip methods (note I used a trailing debounce instead of throttle just to make sure that the method is always called at the end of every burst of scroll events).
See a working example: https://codesandbox.io/s/r5393l62pm
That's a really nice simple example - thanks! I think it'd be good to add a link in the Readme or in the examples page - anyone want to do a PR?
You have to place the tooltips outside of the virtualized area and have them be not virtualized. The way absolute positioning works within the virtualized area is pretty tough because you need to know how many items are rendered above an arbitrary point in the virtualized list.
So we build the tooltips first:
const tooltips = projects.map(({ id }) => <ReactTooltip id={id} key={id} effect="solid" />);And then place them outside of the virtualized list:
render () { <List onScroll={ _.throttle(() => { ReactTooltip.rebuild(); ReactTooltip.hide(); }, 200) }> </List> {tooltips} }
the onScroll part is really important, otherwise it is not going to work
I ended up using Material UI tooltip, it works out of the box https://mui.com/components/tooltips/
@angel-langdon How do you think the material UI tooltip and this project compare? Are there missing features? Would you recommended it generally, or only in specific cases?
Since this project is not actively developed, it might be nice to gather some recommendations like this...
@aronhelser I am not an expert in react-tooltip nor Material UI but Material UI tooltip works out of the box even in the react-virtualized context, no need for weird code (technical debt) in onScroll event handler.
You have to place the tooltips outside of the virtualized area and have them be not virtualized. The way absolute positioning works within the virtualized area is pretty tough because you need to know how many items are rendered above an arbitrary point in the virtualized list. So we build the tooltips first:
const tooltips = projects.map(({ id }) => <ReactTooltip id={id} key={id} effect="solid" />);And then place them outside of the virtualized list:
render () { <List onScroll={ _.throttle(() => { ReactTooltip.rebuild(); ReactTooltip.hide(); }, 200) }> </List> {tooltips} }the onScroll part is really important, otherwise it is not going to work
and if have a list of 500 projects it's not good to render 500 Tooltip
Hi @aanbari1337, this issue is related to v4.
Can you please take a look at V5 docs?
https://react-tooltip.com/docs/examples/multiple-anchors
In this doc, you can have one tooltip for 500 anchor elements.