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

Incorporate multiple array values within an if statement

Looking to dynamically change the background image of an element based on specific strings in the URL. Rather than changing it for each individual term like "Site1", I want to be able to target multiple words. Here's what I've tried: var urlstri ...

sidebar that appears upon the initial page load

I'm currently working on implementing a sidebar navigation panel for my website using JavaScript, HTML, and CSS. However, I am facing an issue where the sidebar automatically opens when the page is first loaded, even before clicking on the icon to ope ...

Checking the availability of a username by sending an Ajax request every time the user types it may lead to inefficiencies and slower response times. Are there

I have developed a NodeJS authentication application. In this scenario, when a user enters a username, the system will display "username taken" if it is already in use, otherwise it will show "username available". I am interested in understanding the lim ...

Generate text in reStructuredText with columns

I'm attempting to style a reStructuredText segment in the following layout: type1 : this type4 : this type7 : this type2 : this type5 : this type8 : this type3 : this type6 : this type9 : this I want to fill the page with tex ...

Can someone assist me in retrieving the information stored within an object?

I'm currently working on a Discord bot and I am in need of the user ID, specifically 'xxx', but I'm unsure of how to retrieve it. Here is what I have tried so far: n.mentions.users.User. -- n.mentions.users.User() This is what my code ...

"Upon pressing the submit button in the router.post function, a null value appears

In my form, I am attempting to redirect the page to the home URL after clicking the submit button. However, using res.redirect('/home') is not achieving the desired result. I have also tried using console.log("testing");, but that is not working ...

Is there a way for me to adjust the font size across the entire page?

Most CSS classes come with a fixed font-size value already set. For instance: font-size: 16px font-size: 14px etc. Is there a way to increase the font size of the entire page by 110%? For example, font-size: 16px -> 17.6 font-size: 14px -> 15.4 ...

Receiving unexpected results when returning a function within a React hook

I'm currently working on developing a custom React hook that will provide users with a function to execute. This hook is designed to generate a function internally. Check out this simplified example // fetch.js import { useEffect, useState} from &qu ...

What is the best way to retrieve the primaryText value within the onChange function of a SelectField component?

I am trying to access the primaryText from the onChange method of SelectField. However, onChange only provides (event,index,value). Here is my code snippet: <SelectField value={props.value} onChange={this.handleChange}> {props.opt ...

What is the best way to ensure that the input areas stretch all the way to the edge of the screen?

This form is structured similar to Bootstrap: HTML: <div class="container"> <div class="row"> <div class="form-group row-group"> <label class="col-6">First name</label> <input class="col-6" type="text" v ...

What steps can I take to stop the browser from refreshing a POST route in Express?

Currently, I am using node along with stripe integration for managing payments. My application includes a /charge route that collects various parameters from the front end and generates a receipt. I am faced with a challenge on how to redirect from a POST ...

What is the best way to refine an array by comparing values in both the header and content?

List of items for filtering: [ { itemName: "Apples", category: [ { type: "Red Delicious", description: "Sweet and crunchy red apples" ...

Tips on making a multiline label using html

Can anyone help me with creating a multiline label in HTML and MVC3 using Razor engine? I would appreciate any ideas. Thank you! ...

A guide on invoking a function within a nested or local function

When the code below is executed in a local function, such as the one inside s3.getObject, it throws an error stating that setState is not a function. s3.getObject({ Bucket: bucket, Key: key }, function (error, data) { if (error != ...

Issue with Font Awesome 5 icons not displaying properly after integrating Bootstrap

Trying to spruce up my buttons by adding some fontawesome icons from bootstrap. The icons I'm using are: fas fa-user fas fa-users They display fine without any styling. However, when I apply the bootstrap button css, the "fa-users" icon appears as ...

Submitting POST data from a form to the current page

I am facing a rather complex issue. Currently, on a page, I have a form that collects information from my visitors. With the help of a script, I can grab this information and add it to a specific link. Initially, I used redirect.php to attach the data to ...

Continuously incorporating Ajax requests into a queue

I'm currently tackling a new feature at work and find myself at a crucial point. Despite being unfamiliar with Ajax, I am determined to set up a manual queue to handle the requests instead of relying on the browser. After some research and referring t ...

The issue of Ajax response not triggering the ng-click function

When attempting to pass data through an AJAX return, I encountered an issue with a function that writes an ng-click in Angular 1. The code snippet is as follows: $.ajax({ 'method': 'GET', 'url': base_url +&apos ...

What is the best way to ensure that a <div> extends all the way to the bottom?

My goal is to have this element reach the bottom of the screen, but I also have a header which complicates things. Setting height: 100%; or 100vh results in the page being too big and scrollable. I don't want to manually calculate it because of respon ...

What does Auth.signIn() return in React Native?

I have been working on a project using React Native and Amazon AWS as the backend, and I am utilizing the amplify library. When it comes to logging in, I am making use of the following method: const user = await Auth.signIn(...) Some of my questions rev ...