question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Best way to display multiple data in tooltip

See original GitHub issue

I would like to show a title and a description in each of my tooltips. Something like below:

        {badges.map(badge => (
          <FlexCol xs={4} sm={3} className="badge" key={badge.pk}>
            <img
              className="badge-image"
              src={urljoin(MEDIA_URL, badge.imageUrl)}
              alt={badge.name}
              data-multiline
              data-tip={badge}
              data-for="badge-tooltip"
            />
            <ReactTooltip
              id="badge-tooltip"
              getContent={({name, description}) => (
                <React.Fragment>
                  <p>
                    <strong>{name}</strong>
                  </p>
                  <p>{description}</p>
                </React.Fragment>
              )}
            />
          </FlexCol>
        }

The problem is, html5 data attributes only seem to handle strings, so we cannot send arrays or objects to it. I currently cannot see any other solution than concatenating my 2 data items in data-tip, when split it within getContent, which is far from optimal.

Would it be possible to handle any data-tip-* attribute for me to set data-tip-name and data-tip-description attributes, and easily reuse them from getContent ?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
oriukencommented, May 3, 2019

I did something very similar but using JSON.parse and JSON.stringify so I can manage the whole element and have more flexibility.

So instead of using const [name, description] = dataTip.split("|"); I did something like const obj = JSON.parse(dataTip) Here I can access obj.name and obj.description

And when passing the values, Instead of data-tip={${name}|${description}} I did: data-tip={JSON.stringify(the_object)} Where ‘the_object’ is the element that contains a name and description attributes

4reactions
oladharicommented, Mar 11, 2019

@mtsalenc here the solution that we came with we created a function that handle the content in a customized component for the tooltip:


  handleContent = dataTip => {
    ReactTooltip.rebuild();
    if (!dataTip) {
      return "";
    }
    const [name, description] = dataTip.split("|");
    

    return description ? (
      <p>
        <strong>{name}</strong> <br />
        {description}
      </p>
    ) : null;
  };

in the component using the tooltip you just pass the data-tip like this:

data-tip={`${name}|${description}`}

hope it is helpful

Read more comments on GitHub >

github_iconTop Results From Across the Web

display multiple values for a field in Tooltip - Tableau Community
in Tooltip, a field can be displayed only if it has one value in the category selected, if multiple values, it displays as...
Read more >
Best way to display multiple data in tooltip · Issue #420 - GitHub
I would like to show a title and a description in each of my tooltips. Something like below: {badges.map(badge => (
Read more >
Display multiple tooltips based on maximum and minimum of ...
Background: I have a chart with a data source. This chart has a tooltip enabled so that when a user presses one of...
Read more >
How to show multiple fields from data in tooltip in a multi ...
I have two jsondata objects and I want to display multiple charts in the same highchart. One of the data objects have multiple...
Read more >
How can I show multiple values on a tooltip from a table?
In this example, the tooltip will show only message field value. As per your requirement, you want to display other field data in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found