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

Incrementing and decrementing a variable within the scope in AngularJS

Objective: When the next/previous button is clicked, the label on the current slide should change to display the next/previous category. View the Category Slider Wireframe for reference. Context: I previously tried a solution called 'Obtain Next/Prev ...

Transforming an Ext.data.TreeStore data structure into a JSON format

How can I convert an Ext.data.TreeStore to a string for saving to Local Storage? I tried using Ext.encode() but it's giving me a circular structure error. Has anyone encountered this issue and found a workaround? ...

Variety of typography styles found within the Material UI design system

I am currently working with the Material UI and trying to implement the Typography component. I have noticed that if I do not specify a variant in the typography tag, everything works fine. <div className="login-details"> <Typography&g ...

Compilation of Next.js with Supabase resulted in an error

While working on a project with Next.js and Supabase, everything was going smoothly until I added a table and generated TypeScript Definitions from the PostgreSQL schema using Supabase CLI. The problem arose when I tried running the "npm run build" command ...

The user data stored in the useContext() in React.js may not be complete until the page has finished loading and all

I worked on a project using React. In the main App.js file (the entry point of the application), I fetched the current user data from an API in this manner. function App() { const [user, setUser] = useState(null); const [isLoading, setIsLoadin ...

The text color remains the same even after the method has returned a value

I have a vuex query that returns a list of books. I want to display each book with a specific color based on its status. I tried using a method to determine the color name for each book and bind it to the v-icon, but it's not working as expected - no ...

Exploring an array using bluebird promises

I am currently facing an issue where I need to iterate over an array containing promises. My goal is to multiply all the values in the array by 2 and then return the updated array: var Bluebird = Promise.noConflict(); var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9 ...

In search of a screenplay that mirrors a specific scenario

I recently came across this website: One interesting feature is that all the content loads dynamically on the same page. Instead of loading separate pages, it pauses to fetch the content before smoothly scrolling to the correct section. ...

Creating a seamless integration between a multi-step form in React and React Router

I've been learning how to use React + ReactRouter in order to create a multi-step form. After getting the example working from this link: , I encountered an issue. The problem with the example is that it doesn't utilize ReactRouter, causing the ...

What is the best way to modify the main color for each resource in react-admin?

I have a unique setup where each resource screen inside the react-admin Admin component has a different primary colour to represent the section and content type. I need to find a way to pass a specific theme object variable of primary colour to each resour ...

Problem with geocoding to retrieve a list of terrestrial coordinates

I am currently working on developing a functionality that can return an array of land-based coordinates. I have utilized Google's geocoder to create individual land-based coordinates successfully, but now I want to implement it in a way where an array ...

How can I align a mapped button to appear on the opposite side of the data using Tailwind CSS?

I've been struggling to find a straightforward solution to this issue for a while now. Let me break it down - I need to display some data on the left side of a post card component with a button located right next to it. Here's an illustration: ...

Incorporate the teachings of removing the nullable object key when its value is anything but 'true'

When working with Angular, I have encountered a scenario where my interface includes a nullable boolean property. However, as a developer and maintainer of the system, I know that this property only serves a purpose when it is set to 'true'. Henc ...

Setting up Webpack for react-pdf in a Next.js application

In my Next.js application, I am utilizing the react-pdf library to generate and handle PDF files on the client side without involving the server. However, I am facing challenges in setting up Webpack for Next.js as I lack sufficient expertise in this area. ...

Having Trouble Accessing Dialog Ref with React Hooks and Material-UI When useEffect Runs for the First Time

I am facing an issue where I am unable to obtain a reference to the DOM Node of a material-ui Dialog when my component first loads. The reference always returns as undefined. Here is the code snippet: import React, { useEffect, useRef } from "react"; impo ...

Preventing users from navigating away from the page without choosing an answer in a React application

My dilemma involves the implementation of a question component, where I aim to prevent users from leaving a page without selecting an answer. Below is my question component: import React, { Component } from 'react'; import { Link } from 're ...

Default parameter in Node.js is set when the callback function is the last parameter

Here's a simplified version of the function I'm working with: doSmthg (name, age, callback) { callback(name, age); } I want to set a default value for age if it's not provided. In ES6, I could do doSmthg(name, callback, age=42) {...}, b ...

Where can I find the Cypress.json file for Angular integration with Cypress using Cucumber?

We are currently transitioning from Protractor to Cypress utilizing Cucumber with the help of cypress-cucumber-preprocessor. While searching for Angular documentation on this setup, including resources like , all references lead to an automatically generat ...

Issues encountered with Nextjs 13.4 and Next-Auth 4.2 regarding the signIn("credentials", { }); functionality not functioning as expected

When using next-auth credentials in my current project, I encountered an issue with the signIn() function from next-auth/react. It appears that the redirection to the admin page persists regardless of whether the login details are correct or not. {error: n ...

When attempting to retrieve data saved to req.session with express-session from a different endpoint, the data appears to be

While working on my project with express-session, I encountered a peculiar issue. I am saving the currently logged in user to the session, but when I try to access the currentUser key on the get route, I find that the value is an empty object. Strangely, i ...