ArthurJ
ArthurJ

Reputation: 849

Change default material ui radio checked color

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',
    },
  }}
/>

Upvotes: 2

Views: 2375

Answers (1)

Dmitriif
Dmitriif

Reputation: 2433

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

Upvotes: 3

Related Questions