It is not possible to highlight the text that appears in the title of the tooltip in React MUI

Within my react application, there is a component that utilizes the code snippet below:

<FormControlLabel
    labelPlacement="top"
    control={
      comp?.manualInput ? (
        <TextField
          name="price"
          type="number"
          variant="standard"
          value={comp.price}
          onChange={handleTextValueChange}
          sx={{ width: "150px" }}
        />
      ) : (
        <Box display="flex" alignItems="center">
          <TextField
            name="price"
            type="number"
            variant="standard"
            value={comp.price}
            onChange={handleTextValueChange}
            InputProps={{ readOnly: true }}
            sx={{ width: "150px" }}
          />
          <Tooltip
            title={
              comp.access &&
              comp.access.length > 0 ? (
                <Box>
                  {comp.comp.map((acc, index) => (
                    <Box key={index} sx={{ mb: 1 }}>
                      <strong>Type:</strong>
                      <br />
                      Id: {acc.id}
                      <br />
                      Description: {acc.description}
                    </Box>
                  ))}
                </Box>
              ) : (
                "No Type"
              )
            }
            placement="right"
            arrow
          >
            <InfoIcon
              color={
                comp.access &&
                comp.access.length > 0
                  ? "success"
                  : "action"
              }
              fontSize="small"
              style={{
                cursor: "pointer",
                marginTop: "-4rem",
              }}
            />
          </Tooltip>
        </Box>
      )
    }
    label="Price per Part"
  />

When I hover over the info icon, the tooltip opens and displays the content of the title inside. However, I am unable to select the content by simply clicking on it. Is MUI affecting the styling? What could be missing here? I previously used a tooltip with a simple string in the title without any JSX, and I was able to select it directly. In this case, I had to include a box with JSX. I tried using

<Box sx = {{ pointerEvents: 'auto' }}>
, but it did not have any effect.

Answer №1

The problem you are facing with the Material-UI (MUI) tooltip could be due to its default behavior, which restricts interaction with the content. When a complex JSX structure is used in the title prop, the content becomes non-interactive by default, making text selection difficult.

To enable content selection in the tooltip, you can adjust the Tooltip component's pointerEvents CSS property. This can be achieved by customizing the Tooltip component using MUI's sx prop or creating a custom styled component.

<Tooltip
  title={
    <Box sx={{ pointerEvents: 'auto' }}>
      {comp.access && comp.access.length > 0 ? (
        <Box>
          {comp.access.map((acc, index) => (
            <Box key={index} sx={{ mb: 1 }}>
              <strong>Type:</strong>
              <br />
              Id: {acc.id}
              <br />
              Description: {acc.description}
            </Box>
          ))}
        </Box>
      ) : (
        "No Type"
      )}
    </Box>
  }
  placement="right"
  arrow
>
  <InfoIcon
    color={comp.access && comp.access.length > 0 ? "success" : "action"}
    fontSize="small"
    style={{ cursor: "pointer", marginTop: "-4rem" }}
  />
</Tooltip>



<Box sx={{ pointerEvents: 'auto' }}>

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

Finding a specific cell in a Django HTML table: tips and tricks

Recently delving into django and its intricacies. Struggling to grasp the concept of accurately pinpointing a specific cell within an html table. Yearning to modify the background color of select cells based on certain conditions derived from the generate ...

Arrange divs on the screen in a specific formation

I am exploring ways to position specific divs in the middle of the screen to create a pearl necklace-like shape. The desired shape is as follows: 0 0 0 0 0 0 0 0 0 0 My aim is to achieve this using jQuery on a mobile ...

Guide on incorporating a slash into a React Router path

I have just finished creating a new page using React, and the route for this page is: http://example.com/page1 Upon loading the URL, I realized the need to add a slash at the end like so: http://example.com/page1/ The routes in my code look like this: ...

The component 'ProtectRoute' cannot be utilized within JSX

While using typescript with nextjs, I encountered an issue as illustrated in the image. When I try to use a component as a JSX element, typescript displays the message: ProtectRoute' cannot be used as a JSX component. import { PropsWithChildren } from ...

New Ways to Style the Final Element in a PHP Array - Part 2

So, here's the current challenge I'm facing along with a detailed explanation of what I'm trying to achieve. Initially, following your suggestions worked smoothly; however, things took a drastic turn when I altered the ORDER BY field and int ...

Retrieving information from the Header element (<H></H>) with the help of Selenium

I have a website with the following code snippet: <div class="list_item_normal"> <div class="main_content"> <div class="img_wrap"> <a href="/home/Detaljer/9781118093757"><img alt="Miniaturebillede af omslaget til Op ...

Arrange pictures and div elements in a horizontal layout

I am facing an issue with my code that is displaying 5 'cards' in a messed up layout instead of a straight line. I have tried to align them vertically, but some are still higher and not in the right positions. For reference, I want the layout to ...

What is the best location for the frontend server code within an application built using create-react-app?

After using create-react-app to create my app, I am looking to log messages in the server console. Any advice on how to achieve this? I attempted adding index.js to the root folder and creating a server folder, but so far it hasn't been successful. ...

Error: The "map" property cannot be read if it is undefined in a Django and React application

While I was following the react and django tutorial, I encountered an issue when I added some code for concern with. The error message 'Cannot read property 'map' of undefined' keeps getting thrown. The error location is pointed out ...

Transferring information from one page to the next

How can I efficiently transfer a large amount of user-filled data, including images, between pages in Next.js? I've searched through the Next.js documentation, but haven't found a solution yet. ...

My goal is to enhance the error notifications displayed on the registration form for submitting information

I am currently using Material-UI within a React application to build a web form. While working on my project, I encountered the "TypeError: Cannot read properties of undefined (reading 'filter')" error message in the components/Questionnaire.js ...

Which is better for React: Bootstrap or Material UI?

In my experience working on various projects, I have encountered the situation where I need to incorporate a Material UI component into a bootstrap component. Surprisingly, this integration has worked seamlessly and the user interface appears as expected ...

What is the best way to adjust a Material UI table cell so that the text inside it spans two lines instead of just one?

Looking to enhance the native Material UI cell to display two lines of text with ellipsis instead of just one. Unfortunately, adding divs inside the cell and applying styles won't work due to the current implementation of the table. This is the curre ...

When I include scroll-snap-type: y; in the body tag, the scroll-snapping feature does not function properly

Hey there! I've been trying to implement scroll-snapping on my project but unfortunately, I couldn't get it to work. I tested it out on both Chrome and Firefox, but no luck so far. Here's the code snippet I've been working with, would a ...

Creating a React App Production Error Boundary that is mapped to the source code involves following a few steps to

I have implemented an error boundary component to effectively capture react errors, which is working fine. However, I am facing an issue in the production app where the logging seems inefficient due to the unorganized component stack structure: \n ...

Enhance Your Cards with Hover Zoom Text

I'm looking to place some text in front of a card hover zoom effect, but currently it appears behind the zoomed image upon hover. <div style="margin-top: 50px;" class="container imgzoom"> <div class="row ...

Mobile users are unable to access the form

Welcome to my website ! I encounter an issue where I can successfully submit a form on the desktop version, but it seems that the "Next" button below the form is not clickable on mobile. I would greatly appreciate any assistance in resolving this matter. ...

I need to condense my layout from three columns to just two columns in HTML

The html code for "Date Accessed" is meant to be in one column as a header, while the actual dates should be in another column, but somehow they are all appearing in a single column. I am having trouble figuring out why. <!DOCTYPE html> {% load stati ...

Combining data from API endpoints

After gaining access to the API and storing the data using useState in my React project, I have encountered a challenge. How can I efficiently calculate the sum of values from two different divs without resorting to jQuery? I want to keep the code clean ...

What is the best way to remove the hover effect from a specific element within a div?

I am looking to achieve a specific hover effect where the white part does not darken when hovering over a certain element within its child elements. Here is the HTML code I have: <div className= {css.searchBarDiv}> <div className={css.searchBar ...