Optimizing the FormControlLabel with the label prop

I'm attempting to nest a RadioGroup inside AccordionDetails, and then add the Accordion list as options within an Autocomplete component in its renderOption props.

The issue I'm encountering is that when clicking on the label (which is a span element upon inspection) of the radio button, it closes the Autocomplete dropdown without saving the selected value to state.

Thank you in advance!

View the Codesandbox: https://codesandbox.io/s/material-demo-forked-brun8?file=/demo.js

Answer №1

Remember to call e.stopPropagation() when clicking on the label panel

function customizeLabel({ name, rating }) {
    return (
        <div
            rating={rating}
            onClick={(e) => {
                setRating(e.target.getAttribute("rating"));
                e.stopPropagation();
            }}
        >
            {name}
        </div>
    );
}

Customized Label:-

<CustomLabel
              rating="5"
              content={<span><Star /></span>}
              name={customizeLabel({ name: "Star", rating: "5" })}
            />

Live Demo -

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

Issue with navigation using arrow keys in Material UI select dropdown

I am facing an issue with the mui multiple select component where I have added a textfield inside. The problem is that the keyboard arrow up and down list navigation is not functioning properly. Instead, when using the arrow keys onkeydown, it focuses on t ...

What is the easiest way to set up a local server for deployment?

I am currently working on a research project with unique requirements that involve using private data which cannot be shared online. However, I need to create a demonstration where this data could potentially be accessed online as part of a proof of concep ...

Utilize MaterialUI's stepper component to jazz up your design with

Is there a way to customize the color of a material ui Stepper? By default, the material UI stepper's icons use the primary color for both "active" and "completed" steps. class HorizontalLinearStepper extends React.Component { state = { activeS ...

Encountered an issue with the MUI DataGrid: TypeError - Unable to access properties of undefined while attempting to read 'MuiDataGrid'

I've been trying to customize the language of the default parameters in my DataGrid MUI configuration, but I'm encountering an error when attempting to add the localeText. I have been following the guidelines provided on their website page titled ...

Is there a peer dependency issue with Node and React?

Currently, I am attempting to utilize a codebase that I discovered while reading an online article. The code can be found at: https://github.com/kangzeroo/Kangzeroos-AWS-Cognito-Boilerplate You can access the package.json file here: https://github.com/kan ...

What could be the reason for the error message "module 'msw' does not export a member named rest" when trying to import "import { rest } from 'msw'"?

I am trying to implement the code from the following example: https://testing-library.com/docs/react-testing-library/example-intro/ Specifically, I am looking at the "Step-By-Step" section for the "Imports" where it shows: // import dependencies import R ...

How can I utilize FileReader with Next.js server-side rendering?

I'm currently working on a Next.js app, and I am facing an issue while trying to use FileReader in order to read the contents of an uploaded file. This is how my component is structured: let fileReader; let props = { multiple: false, onRe ...

`Finding it difficult to halt the spread of events in reactJs`

One of my conditions involves a simple dropdown menu: handleDropdown = (e) => { if (e.type === "focus") { console.log("inside dropdown focus"); this.setState({ dropDownDis: "block" }) } else if (e.type === "blur") { console.lo ...

Using the ternary operator will always result in a TRUE outcome

Having trouble with a ternary operator expression. AssociatedItemType.ExRatedTag ? session?.data.reloadRow(ids) : this.reloadItemRows(this.prepareItemsIdentities(ids)!), The AssociatedItemType is an enum. I've noticed that const ? 1 : 2 always retur ...

The utilization of useState can potentially trigger an endless loop

Currently, I am in the process of developing a web application using Next.js and Tailwind CSS. My goal is to pass a set of data between methods by utilizing useState. However, I have encountered an issue where the application loads indefinitely with excess ...

«Modify Apollo Client settings to accommodate JWT authentication»

Is there a way to set up a token in my apollo client when the user logs in? I've been struggling with this issue. This is what I currently have in my index.js: const client = new ApolloClient({ ssrMode: SERVER_MODE, cache: new InMemo ...

Integrating React Final Form with Material UI's Select component

I am encountering an issue with React final-form and Material UI Select. The problem arises when the Select list items are updated, but the previously selected value remains in the form even though it is no longer part of the new list. Let's consider ...

What is the process of applying material-ui component styles to a different React component from a separate library?

For instance: import { CssBaseline, ThemeProvider, Typography } from "@material-ui/core"; // MUI **Typography** component import { Text, RichText } from "@some-library/core"; // some-library's **Text** component const theme = crea ...

Expanding a div to occupy 100% width within a Material UI TableBody

I am struggling to center a CircularProgress component inside a material UI TableBody. I have attempted the following code, but the CircularProgress is not displaying at the center as expected. (Please note that only relevant code has been included) const ...

Is there a way to exclude a specific value from a nested zod scheme?

I'm working with a zod schema where I need to omit certain fields from the schema entirely, instead of just making them optional. Is there a way to achieve this directly in zod? Can fields be omitted or can the schema be preprocessed somehow? For ins ...

Ways to return success state to component without the need to modify the store

I am currently working on a simple form in react-redux with the goal of adding a user to the database and displaying a success message upon successful registration. However, I am unsure of the most effective approach to achieve this. Here is what I have so ...

In React, I aim to select a particular option by clicking on a button, which should then be disabled

In my parent component, I have two components - one of which is a child component. The child component consists of three radio options and a button. My requirement is that upon clicking the button, a specific option should be selected and the button disabl ...

Data can be retrieved in a React/Next.js application when a button is clicked, even if the button is located in a separate

Whenever the button is clicked, my function fetches weather data for the current location. I am trying to figure out how to transfer this data from the Location component to the pages/index.tsx. This is where another component will display the data. This ...

How can I clear the div styling once the onDismiss handler has been triggered

Seeking assistance with resetting a div on a Modal after it has been closed. The issue I am facing with my pop-up is that the div retains the previous styling of display: none instead of reverting to display: flex. I have searched for a solution without su ...

Mixing Module Federation with different React versions and individual CSS isolation

In my setup, the module federation remote repository is: developed using react 17 utilizing material-ui 4 with jss incorporating global CSS from third-party libraries that cannot be modified Meanwhile, I have several hosts that consist of: different ver ...