Tooltips that appear when hovering over elements in a Fixed Data Table

I am looking to incorporate both click and hover events for tooltip content within the cells of the Fixed Data Table component. Currently, I am utilizing react-tippy for tooltips with the use of the html option to create a dropdown menu. While I can display the tooltip, I am facing difficulties in adding additional events for the content inside the tooltips.

The onMouseEnter and onClick events in the .actions-list__item within the ActionCell.jsx are not being triggered.

react-tippy-data-table.firebaseapp.com

https://i.sstatic.net/LhQW2.png

I encountered issues running react-tippy in JSFiddle, hence I deployed an example project on Firebase.

Table.jsx

import React, { Component } from 'react';
// Remaining code from Table.jsx...

ActionCell.jsx

import React from 'react';
// Remaining code from ActionCell.jsx...

Answer №1

My solution involved incorporating the interactive parameter within the context of the react-tippy

Answer №2

<pre>
    import React from 'react';

    import CustomTooltip from './CustomTooltip';

    interface Props {
        className?: string;
        value?: string;
        colSpan?: number;
    };

    interface State {
        isOverflowing: boolean;
    };

    class CustomTableCell extends React.Component<Props, State> {
        private myRef = React.createRef();
        constructor (props: Props) {
            super(props);
            this.state = {
                isOverflowing: false
            }
        }

        handleHover(event: any) {
            if (event.target.scrollWidth > event.target.offsetWidth) {
                this.setState({isOverflowing: true});
            } else {
                this.setState({isOverflowing: false});
            }
        }

        render () {
            return (
                <td colSpan={this.props.colSpan} className={this.props.className}>
                    <span onMouseEnter={this.handleHover.bind(this)} className="overflow-span">
                        {this.props.value}
                    </span>
                    <CustomTooltip
                        isVisible={this.state.isOverflowing}
                        value={this.props.value}>
                    </CustomTooltip>
                </td>
            );
        }
    };

    export default CustomTableCell;

    // Using the custom tooltip component in another file

    import React from 'react';

    interface Props {
        value?: string;
        isVisible?: boolean;
    };

    interface State {};

    class CustomTooltip extends React.Component<Props, State> {
        render () {
            if (this.props.isVisible) {
                return (
                    <span className="custom-tooltip">
                        {this.props.value}
                    </span>
                );
            }
            return (
                <span>
                </span>
            );
        }
    };

    export default CustomTooltip;

    // Corresponding CSS styles

    .custom-tooltip {
      display: none;
      position: absolute; 
      z-index: 100;
      border: 1px;
      background-color:white;
      border-style: solid;
      border-width: 1px;
      border-color:#0c7c84;
      padding: 5px;
      color:#0c7c84;
      font-size: 16px;
      border-radius: 5px;
      top: -50px;
      left: 50px;
      white-space: pre-line;
      word-break: break-all;
      width:100%;
    }
    
    .overflow-span {
      display: inline-block;
      overflow: hidden;
      width: 90%;
      text-overflow: ellipsis;
    }
    
</pre>

You can utilize the custom tooltip component to display a tooltip on hover, where the tooltip is only visible when the data overflows within the table cell.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Fan Animation in CSS

I have three unique images that I would like to animate in a fan-like manner consecutively. I prefer not to merge the images in Photoshop, as I want them to be displayed one after the other. Here is the code snippet (dummy images are used): .bannerimg ...

An embedded object is encountering an error due to an undefined value in the field of 'Math'

My approach involves using AJAX to dynamically load a YouTube video when the page is loaded. $(document).ready(function(){ $.ajax({ url : '/myurl', type:"post", data:{"d": $('#d_id').val()}, ...

What is the best way to include my JavaScript code in a shiny app to ensure all hyperlinks are acknowledged?

Is there a way to query all links using an external script that I integrate into the HTML via renderUI()? Currently, I am getting an empty NodeList []. Could it be related to where I include the script? I have attempted the following setup: R Shiny Scrip ...

Retrieving JSON data every few seconds using JavaScript

I am attempting to continuously read a local JSON file in order to generate a plot. This JSON file is updated every n seconds. To accommodate for the changing file, I am using a combination of $.getJSON() and setInterval() to read the file at regular inter ...

Having trouble executing react-native project using the command "npx react-native run-android"

Hey there! I've been working on a react-native project for quite some time now and everything was going smoothly until yesterday. I encountered an error when running the command npx react-native run-android in Metro before the project had fully execut ...

Retrieving a PHP string and storing it in a jQuery variable

How can I store the following PHP string in a jQuery variable? { '05-10-2018' : '<a href='http:www.google.com/' target='_blank'>Seeing dads differently</a>', '05-10-2018' : '<a href=&ap ...

Generate a Year attribute value using the information from the year field in a JSON document

Currently, I am exploring the functionalities showcased in this example: I am interested in adapting the following code snippet to work with my JSON file, which lacks a specific date data type field but includes a 'Year' value: // Transform Yea ...

Tips for overriding a CSS class without impacting other classes sharing the same name

Within a page filled with various widgets, I am facing an issue where I need to override the container class for a specific widget. However, the problem is that all widgets with the same class name are being impacted. Attached below is a screenshot from in ...

Real-time array filtering with ReactJS for nested arrays

I am currently working on implementing a real-time filtering search feature for a lengthy list of items. The items are structured in the form of an array containing arrays with a string and an object, as shown below: const items = [ ["cats", [ ...

Backbone template fails to display

I recently delved into learning Backbone.js by following this particular example that aimed to change the content within a specific div element. However, I encountered an issue where the content failed to display. Building upon that example, I proceeded t ...

What is the best way to update a Bootstrap Toggle with a dynamic value?

When performing an update action, the user can click on an element in a table and change the value by toggling a bootstrap toggle. However, I am unsure of how and where to apply this change. Here is the code snippet: Initially, the user clicks on the ele ...

Utilizing PHP to retrieve and insert data from a database, then display the information within a div. Despite CSS being configured with different width and height settings, the div expands accordingly

I am currently utilizing PHP to input information into a database and then use that information in a simple comment system. Being new to PHP, I am unsure if there is an easier way to achieve what I am doing. However, I am facing a challenge where if the in ...

Comparing SSE and Ajax Polling for querying in the browser without using JavaScript code

I have been learning about Server Side Events and one key distinction that stands out to me is the way SSE handles server queries compared to Ajax Polling. With Ajax Polling, users are responsible for querying the server after each response, whereas with S ...

Identify when a mouse hovers within 10 pixels of a div using jQuery

Is it possible to detect when a user hovers over a specific area within a div using JavaScript or jQuery, without adding any additional tags? -------------------------------- -------------------------------- -------------------------------- -------- ...

Click the edit button to access the options in the material table

https://i.stack.imgur.com/Inyow.png Currently, I am utilizing Material Table within Reactjs to display the table Data. However, I have encountered a hurdle where I need to alter state upon clicking on the edit option/icon. My objective is not to modify th ...

Having difficulty adjusting the text to match the image alignment

Having trouble aligning the text tag inside the H1 above the image. It keeps appearing in the wrong place, either on the left or right. I've tried including the h1 inside the container, but it just disappears. <!doctype html> <html> <h ...

Tips for alternating the display between parent and child elements using jQuery

I am working with a list that includes parent and children items. Title1 child1 child2 child3 Title2 child1 child2 child3 My goal is to display the parent and children in the following format: title1_child1 title1_child2 title1_child3 title2_chil ...

Is it possible to dynamically adjust the number of children in an array?

As a beginner in React, I've been exploring ways to manage an array of components from a parent component. My task involves creating a site where I can dynamically add or remove names to a list. However, I'm facing a challenge in figuring out the ...

Utilize LESS Bootstrap as a guide for incorporating content

I have been struggling to properly integrate Bootstrap into my LESS file. Currently, I am adding Bootstrap to my project using NPM. If I simply use the following import statement in my LESS file: @import (reference) 'node_modules/bootstrap/less/boot ...

How to organize items in an array based on paired values using Angular or Javascript?

In my current scenario, I am working with a substantial array containing 120 objects. Each object within the array possesses an id value and an opposite_id value, essentially forming pairs. I'm looking for the most efficient approach to iterate throug ...