React-tooltip: Tooltip does not work when using unique IDs within a table component

Created on 12 Oct 2016  路  11Comments  路  Source: wwayne/react-tooltip

I'm actually using ag-grid to render some html along with ReactTooltip in a cell of a table. I actually use React components to render each cell and within each react component, I embed an unique ReactTooltip. I actually want to hover a validation error if the cell has an error from user input.

In my render method, I have the following

return (
                <div>
                    <ReactTooltip id={uniqueID} type="error" effect="float" />
                       <div data-tip data-for={uniqueID} >
                               {cell.stringValue}
                    </div>
                </div>
            );

It's weird, just for testing purposes I used a static and constant string for the id, the tool tip will render on the first render but after the cell is rerendered, the tooltip disappears.

Gif of ReactTooltips having the same ID:
tooltipbug

Gif of me inspecting the cell and the html markup of the corresponding ReactToolTip

tooltip1

When do I use uniqueIDs for each ReactTooltip within a cell of a table, the tooltip simply does not show.

Gif of ReactTooltips having unique IDs with the same exact code, everything is the same exact uniqueID is different for each cell and each id of ReactToolTip

tooltipbug2

I've tried putting ReactTooltip.rebind() in my React Component's componentDidUpdate() for each cell in hopes of tooltips being associated with the appropriate cell but to no avail.

Any input would be much appreciated.

Most helpful comment

I had a similar issue: I had a table of tasks and the tooltip wouldn't show when clicking on the one of the edit buttons.
Screen Shot 2020-05-23 at 7 26 01 AM

What I ended up doing was calling rebuild in componentDidMount

 componentDidMount() {
    this.setState({...someState I had to set first}, () => ReactTooltip.rebuild()
 }

I'm using reactTooltip's getContent function to customize my tooltip:

Screen Shot 2020-05-23 at 7 32 24 AM

Hope it helps

All 11 comments

@dkwin You can try putting the <ReactTooltip /> out of the cell, for example, you can put it under className='ag-body-container'

I see some weird behaviour with the tooltip not working for instances where you map over a collection and render some items (for instance tds). I can only get it to work if I nest a ReactTooltip for each cell element, which is horribly inefficient.

I am a little strapped for time, else I will try to get a fiddle up which replicates the issue.

Was there any resolution to this issue?

Any resolution?

Also trying to use this in ag-grid and experiencing some weird results when new cells that use tooltips are rendered into the viewport.

I have the same problem, any solution???

I solved it using ReactTooltip.show and hide

<span className={style.mainBox} ref={(c) => { this.ref = c; }} 
      data-tip={`${item.name} ID`} data-for={id}
      onMouseOver={() => { ReactTooltip.show(this.ref); }}
      onMouseLeave={() => { ReactTooltip.hide(this.ref); }}
>
  {template}
  {isLastItem ? null: ', '}
  <ReactTooltip id={id} place="top" className="tooltip" type="light" />
</span>

Works fine for me with ag-grid cells now

Not sure if that will help you, but to those having issues with the tooltip locking in to only one id, I just pass this prop tooltipId={Math.random().toString(36).substr(2, 5)} to my ReactTooltip and lots of bugs are solved.

I solved it using ReactTooltip.show and hide

<span className={style.mainBox} ref={(c) => { this.ref = c; }} 
      data-tip={`${item.name} ID`} data-for={id}
      onMouseOver={() => { ReactTooltip.show(this.ref); }}
      onMouseLeave={() => { ReactTooltip.hide(this.ref); }}
>
  {template}
  {isLastItem ? null: ', '}
  <ReactTooltip id={id} place="top" className="tooltip" type="light" />
</span>

Works fine for me with ag-grid cells now

Problem I am having with this approach is I am having two tips at the same time- one that I pointed and the other one is the last tip element. Here is the screenshot.
Untitled

I had a similar issue: I had a table of tasks and the tooltip wouldn't show when clicking on the one of the edit buttons.
Screen Shot 2020-05-23 at 7 26 01 AM

What I ended up doing was calling rebuild in componentDidMount

 componentDidMount() {
    this.setState({...someState I had to set first}, () => ReactTooltip.rebuild()
 }

I'm using reactTooltip's getContent function to customize my tooltip:

Screen Shot 2020-05-23 at 7 32 24 AM

Hope it helps

Thanks! It helped.

Was this page helpful?
0 / 5 - 0 ratings