2

I have taken a look at other threads relating to this but unfortunately I am not able to change the material ui default red checked colour.

Here is my code below:

   return (
        <FormControl>
            <FormLabel>{label}</FormLabel>
            <RadioGroup row
                name={name}
                value={value}
                onChange={onChange}
                {
                    items.map(
                        item => (
                            <FormControlLabel key={item.id} value={item.id} control={<Radio />} label={item.title} />
                        )
                    )
                }
            </RadioGroup>
        </FormControl>
    )

I simply want to be able to change the checked radio color from red to blue.

I have tried the following but didn't work:

<Radio
  {...props}
  sx={{
    '&, &.Mui-checked': {
      color: 'blue',
    },
  }}
/>

1 Answer 1

3

Because you use 2 selectors - & and &.Mui-checked you overwrite the color of your checkbox in an unchecked state. Therefore, you should get rid of & and everything will work fine:

      <Radio
        {...props}
        sx={{
          color: "red",
          "&.Mui-checked": {
            color: "green"
          }
        }}
      />

Demo

3
  • Based on your solution and my code - where exactly do I place this code within my code as I entered this within control={<Radio sx={{color: "red", &.Mui-checked": { color: "green" }}}/>} but it made no difference. Is this the correct place for this code or do I need to place it somewhere else?
    – ArthurJ
    Commented Apr 13, 2022 at 0:06
  • Yeah, from what I see you placed the required code correctly. I added FormControl, FormLabel, RadioGroup and FormControlLabel components to my demo in the answer to make it as closely as possible to your case and it works. If it makes no difference in the UI it's more likely that the issue has something to do with other components/styles and it'd be easier to help if there was a reproduction example in codesandbox.
    – Dmitriif
    Commented Apr 13, 2022 at 3:38
  • 1
    I think you may be right but in the end, I managed to get it working with the following change: control={<Radio color="primary"/>} and basically picked my my theme colour.
    – ArthurJ
    Commented Apr 13, 2022 at 6:09

Not the answer you're looking for? Browse other questions tagged or ask your own question.