What is the best method to display a tooltip for a disabled radio button within a set of radio buttons?

Is there a way to disable a specific radio button based on a condition and display a tooltip only for that disabled button?

https://i.stack.imgur.com/niZK1.png

import {Tooltip} from '@mui/material'; 
   
           <Tooltip
              title={
                <div>
                  <span>Tooltip message</span>
                  <a
                    href={links}
                    target="_blank"
                    rel="noopener noreferrer"
                    style={{ color: 'blue', textDecoration: 'underline' }}
                  >
                    linktext
                  </a>
                </div>
              }
              arrow
              placement="bottom-start"
            >
             
                <RadioListComponent
                  row
                  aria-labelledby="classname"
                  defaultValue="one"
                  sx={{//style } }}
                  items={listArray.map((option) => ({
                    ...option,
                    sx: {
                      ...option.sx,
                      pointerEvents: option.value === 'two' && !enabled ? 'none' : 'auto',
                      opacity: option.value === 'two' && !enabled ? 0.5 : 1,
                    },
                  }))}
                  {...field}
                />
            </Tooltip>

RadioListComponent

const Radio = forwardRef((props: RadioProps, ref: RefType) => {
const { items, action, ...radioGroupProps } = props;
return n (
  <MuiRadioGroup {...radioGroupProps} ref={ref}>
  {items.map((item, index) => (
    <FormControlLabel
      value={item.value}
      onClick={action}
      control={<MuiRadio aria-label={item.label} />}
      label={
        <>
              <Typography component="span" sx={{//style }}>
                {item.label}
              </Typography>
            </Tooltip>
          <Typography component="span" sx={{ //style }}>
            {item.label}
          </Typography>
        </>
      }
      sx={item.sx}
    />
  ))}
</MuiRadioGroup>
);
});

The issue is with the tooltip displaying when hovering over any radio button, which shouldn't be the case. How can this be resolved? Any suggestions are appreciated. Thank you!

Answer №1

If your listArray contains options and their values with the enabled property, you can customize the MuiRadioGroup component as shown below:

{
   item.enabled ? <FormControlLabel
      value={item.value}
      onClick={action}
      control={<MuiRadio aria-label={item.label} />}
      label={
        <>
              <Typography component="span" sx={{//style }}>
                {item.label}
              </Typography>
            </Tooltip>
          <Typography component="span" sx={{ //style }}>
            {item.label}
          </Typography>
        </>
      }
      sx={item.sx}
    /> :      <Tooltip
              title={
                <div>
                  <span>Tooltip message</span>
                  <a
                    href={links}
                    target="_blank"
                    rel="noopener noreferrer"
                    style={{ color: 'blue', textDecoration: 'underline' }}
                  >
                    linktext
                  </a>
                </div>
              }
              arrow
              placement="bottom-start"
            >
                   <FormControlLabel
      value={item.value}
      onClick={action}
      control={<MuiRadio aria-label={item.label} />}
      label={
        <>
              <Typography component="span" sx={{//style }}>
                {item.label}
              </Typography>
            </Tooltip>
          <Typography component="span" sx={{ //style }}>
            {item.label}
          </Typography>
        </>
      }
      sx={item.sx}
    />
    </Tooltip>

}

Please excuse any formatting issues, but hopefully, you understand the gist of what I'm trying to convey. There are also several ways to shorten this code.

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

Tips for determining if a player (canvas) is in contact with a drawn wall for collision detection

I created a 2D map using the canvas HTML element where I drew a red square to represent the player and a light blue wall underneath it. I am looking for a way to detect if the player (red square) is in contact with the wall (light blue). The elements do no ...

Stop working to $(this) in jquery when clicking outside

I'm facing an issue with my code and would like some help. I have a button that toggles the visibility of a filter element, which is working fine. However, I now want to implement a "click outside" effect to close the filter when clicking on any body ...

The Mongoose model is having issues being imported into a different Component

Attempting to utilize my model for displaying and locating users in MongoDB has hit a snag. Upon importing it into profile.js and launching my app, an error is thrown: Cannot read properties of undefined (reading 'Users') https://i.stack.imgur.c ...

After using `setAttribute`, React is unable to produce any audio

Currently, I am facing an issue with a React component where it should play sound from an array of IDs stored in the database by setting the ID to the src attribute for the source tag. However, this functionality is not working as expected. Interestingly, ...

Is it possible to create a looped GLTF animation in three.js using random time intervals?

I am currently exploring the world of game development with Three.js and have a specific query regarding animating a GLTF model. Is it possible to animate the model at random intervals instead of in a continuous loop? In the game I am creating, players wil ...

Distinguishing a button based on its class

I am currently designing a website to showcase personalized store products. Each product info box includes a button, as shown in the screenshot below: https://i.sstatic.net/hiXiY.png Upon clicking on the "Options" button, users can view information about ...

Updating the content of a window without the need to refresh the page using JavaScript

Is there a way to navigate back to the previous window in chat_user without refreshing the entire page when the back button is clicked? Below is the code I have tried: <a href="" onclick="window.history.go(-1); return false;">back</a> ...

What could be causing the issue with this function not loading correctly the first time in Node.JS?

I am currently in the process of developing a Twitter bot using Node.JS. One issue I am facing is with a function that utilizes an npm library called "scrapejs" to extract data from Yahoo Finance. The problem arises when this function loads after the initi ...

Anyone have a sample showcasing the integration of VueJS with the latest webpack 4 configuration?

VueJs templates now come with numerous examples and starting project skeletons. However, most of them still utilize webpack v3. Has anyone experimented with webpack 4? I'd love to see how you integrate version 4 of webpack into a VueJs project. Thank ...

Paypal Payment Plans on a Monthly Basis Utilizing the Bootstrap Pricing Slider

I came across this fantastic Bootstrap Pricing Slider that I found originally at Within my Bootstrap Pricing Slider, there is a "total amount" calculated after some math, resulting in a final score. The slider includes a "Process" button which currently ...

Comparison of performance between serializing an object to indexedDB and using JSON.stringify

I am curious about the efficiency differences in terms of browser/CPU/memory between using JSON.stringify for serialization versus writing an object to an object store in indexedDB. The context for this question is optimizing the process of writing an obj ...

Material-UI X-Grid encounters a resizing columns issue when utilized in RTL mode

When using the Material UI X-Grid component with an RTL theme, there seems to be an issue with resizing columns. When attempting to expand a column by dragging the left portion of the column separator to the left, it actually shrinks instead. This unexpect ...

Issue with JQuery Ajax: Some users experiencing failure with ajax requests (response code 0)

I've implemented an ajax-based login system where users input their username/password and the data is asynchronously sent to a PHP script for validation. Once validated, the user is logged in or an error message is returned in JSON format. However, I ...

The setTimeout function fails to behave as intended when used in conjunction with synchronous ajax

Within my code, I have a function that is being invoked multiple times due to iterating through an array of length n and creating 'Plants' with synchronous ajax calls. These calls involve querying the Google Maps API, so it is crucial to throttle ...

FireFox is causing issues with both ng-view and Angular functions, rendering them unusable

My AngularJS sample application is running smoothly in Google Chrome, but when I tried to test it in Firefox, I encountered issues with ng-view and other functions not working properly. This is the structure of my application: Index.html <!DOCTYPE ht ...

Creating a custom design for legends in Chart.js

I'm currently working on a project using chart.js and I'm trying to customize the label/legend styling for my chart. My goal is to replace the rectangular legend with a circular one. I've come across the suggestion of creating a custom legen ...

What is preventing me from being able to retrieve the properties of this object in JavaScript?

Recently, I started working on a side project as a way to practice what I learned from a web development course on Udemy. However, I encountered an issue with a middleware function that I wrote. This is the function causing trouble: const User = require(& ...

Why must the sidebar be displayed horizontally on the smartphone screen?

I've been struggling to make the sidebar menu on my smartphone display horizontally with icons at the top and text at the bottom. I've tried using flex and other methods, but it still doesn't work sideways. Am I missing something? const s ...

Is it possible to execute custom JavaScript code in an R Jupyter notebook?

Within my Jupyter Notebook, I am working with the R programming language and would like to integrate javascript functions into it. I'm aware that there are libraries in javascript that can be called from R, but I haven't been able to find any ex ...

Transforming React drag and drop page builder state into a functional html, css, and js layout

Currently, I am in the process of developing a drag and drop UI builder for react-based app frameworks. Before incorporating drag and drop functionality, my main focus is on rendering a page layout based on a structured array stored in the state. I have a ...