How to customize the checkbox color in Material UI?

  • I've been attempting to adjust the color of checkboxes and radio buttons.
  • After conducting some research, I stumbled upon this helpful link: Material UI change Input's active color

  • Unfortunately, I keep encountering the following error:

    (0 , _styles2.createMuiTheme) is not a function

  • Could someone guide me on how to modify checkbox colors for use in other areas?

https://codesandbox.io/s/m7z2l1j09y

const theme = createMuiTheme({
  palette: {
    secondary: {
      main: "#E33E7F"
    },

    formControl: {
      color: "black"
    }
  }
});

<MuiThemeProvider theme={theme}>
          <FormControl component="fieldset" className={classes.formControl}>
            <FormLabel component="legend">Gender</FormLabel>
            <RadioGroup
              aria-label="Gender"
              name="gender1"
              className={classes.group}
              value={this.state.value}
              onChange={this.handleChange}
            >
              {radioValues.map(radio => {
                return (
                  <FormControlLabel
                    value={radio.value}
                    control={<Radio />}
                    label={radio.label}
                  />
                );
              })}
            </RadioGroup>
            {checkBoxvalues.map((check, index) => {
              return (
                <FormControlLabel
                  key={check.value}
                  control={
                    <Checkbox
                      checked={check.checked}
                      onChange={this.handleCheckBoxChange(check.value, index)}
                      value={check.value}
                    />
                  }
                  label={check.label}
                />
              );
            })}
          </FormControl>
        </MuiThemeProvider>

Answer №1

The issue you encountered was a result of an error in the import statement. Instead of using

import { MuiThemeProvider, createMuiTheme } from "material-ui/styles";

You should have used

import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";

In addition, I included the specification of the color property on the Checkbox.

Here is a functional version of your sandbox: https://codesandbox.io/s/w68nm77o0k

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

Integrating fresh components into a JSON structure

I've been attempting to insert a new element into my JSON, but I'm struggling to do it correctly. I've tried numerous approaches and am unsure of what might be causing the issue. INITIAL JSON INPUT { "UnitID":"1148", "UNIT":"202B", "Sp ...

Can you explain the concept of peer dependencies and plugins to me?

After reading numerous articles and posts on the topic of peer dependencies, I still find myself struggling to fully understand the concept. For instance, if coffee 1.0 has a dependency on milk 1.0, then logically coffee 1.0 would be included in my packa ...

AngularJS: resolving route dependencies

I have a variable $scope.question that contains all the questions for the page. My goal is to loop through the questions page by page. To achieve this, I created a function called questionsCtrl and I am calling this function in the config while setting up ...

What is the reason for not being able to access default props in the react constructor but being able to access them in the render method

Why is the initial this.props failing as suggested by the title? And how can you address this situation when you need to access props within your constructor, such as in scenarios involving subscriptions? class AboutBox extends Component { static defa ...

Encountered an error while trying to set up the route due to Router.use() needing

Within my app.js file, I have the following code: app.use('/', require('./routes')); //old routes app.use('/api', require('./api')); Additionally, I have an api folder containing an index.js file. This is what the ...

Encountering a typescript error: Attempting to access [key] in an unsafe manner on an object of

I have recently developed a thorough equality checking function. However, I am encountering an issue with the highlighted lines in my code. Does anyone have any suggestions on how to rectify this problem (or perhaps explain what the error signifies)? Her ...

Checking variable length time with JavaScript Regular Expression

My specific requirement is to validate a string ranging from 1 to 4 characters in length (where H stands for hour and M represents minutes): If the string has 1 character, it should be in the format of H (a digit between 0-9). A 2-character string should ...

Generate table rows by automatically summing the rows and column data using a loop

I'm currently working on a form that dynamically adds data to columns and rows. While I've successfully generated the column names based on database data and used a loop to add details, adding rows has proved to be quite challenging :) Is ther ...

Fill the center circle with GoJs background

Is there a specific way to paint the center circle only? I have provided an example project below. ...

Exploring Android Webview capabilities using HTML 5 geolocation

Utilizing a webview to load a web application, I am using the HTML 5 geolocation API within the page to detect the user's location. While this feature works seamlessly in all browsers and even in an iOS application, I am facing issues getting it to fu ...

The function given to requestAnimationFrame is not being triggered as expected

I have successfully implemented an infinite loop animation using setInterval. However, I want to enhance the performance by switching to requestAnimationFrame(). Unfortunately, the function supplied to requestAnimationFrame() is not being called for some r ...

Obtain information about a div element while scrolling

Looking to enhance my social feed page by adding a view count feature for each post. The challenge is figuring out how to keep track of views as the user scrolls down the page. Any suggestions? ...

What is the best way to dynamically identify the property names of my object?

let weekData = []; for (let i = 0; i < 7; i++) { const weekdayName = moment().subtract('days', i).format('dddd'); weekData.push({ [weekdayName]: 0 }); } I'm trying to create a list of objects with dynamic pr ...

Is the jQuery popup malfunctioning? It appears to be stuck within a div

Currently, I am in the process of developing a website at and I am facing an issue with the hover type menu. Whenever I click on the arrows next to the logo, instead of fully opening up, the menu seems to be getting stuck and is not expanding entirely. I ...

What is the best approach for fetching a refined selection of items from an array of IDs using GraphQL?

If I have a list of products stored in my database, it might look something like this items: [ { id: '001', name: 'Product 01', description: 'Awesome product' price: 50.00 }, { ...

The PHP function is failing to communicate with jQuery and Ajax

Having trouble with PHP return to jQuery/Ajax functionality, When I try to edit an item, the error message displays even though the success function is executed. On the other hand, when attempting to delete an item, nothing is displayed despite the succes ...

Tips on incorporating browser-specific media queries such as -ms-high-contrast and Edge within React Material-UI

Internet Explorer @media only screen and (-ms-high-contrast: active), (-ms-high-contrast: none) { } Microsoft Edge @supports (-ms-ime-align:auto) { } ...

"Utilize AngularJS JavaScript to nest HTML elements within each other for dynamic web

I have developed a unique custom directive called hero. My goal is to set up a nested view for multiple instances of hero. Check out this demo to see it in action. The desired layout looks something like this: <hero a="1"> <hero a="2"> ...

State update failing to modify arrays

Shown below is an array that contains boolean values: const [state, setState] = React.useState({ [`${"checkedA"+index}`]: false, [`${"checkedB"+index}`]: false, [`${"checkedC"+index}`]: false, [`${"checkedD"+index}`]: false, }); ...

Is there a common issue in web browsers? Neglecting the position relative attribute on 'tbody', 'tr', and 'td' elements?

Trying to absolutely position elements within tbody, tr, and td may not work in certain browsers. While it behaves as expected in Firefox, it does not work properly in IE, Edge, and Chrome. If you apply position: relative to tbody, tr, or td, it will be i ...