材质ui更改复选框颜色

时间:2019-05-08 19:52:23

标签: javascript html css reactjs material-ui

  • 我正在尝试更改复选框和单选按钮的颜色。
  • 所以我进行了研究并获得了此链接。 Material UI change Input's active color

  • 但仍然出现错误。 (0 , _styles2.createMuiTheme) is not a function

  • 您能告诉我如何更改复选框的颜色,以便在其他地方使用吗?

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>

1 个答案:

答案 0 :(得分:1)

您的错误是由于import不正确造成的。 代替

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

应该是

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

我还添加了在复选框上指定color属性。

这是您的沙盒的有效版本:https://codesandbox.io/s/w68nm77o0k