复选框:更改根本样式

发布于 2025-02-11 14:52:33 字数 356 浏览 3 评论 0原文

如何在复选框中更改根样式。这行不通。

 <CheckboxItem
                      onChange={()}
                      checked={isChecked}
                      label="Show Checkbox"
                      classes={{ root: classes.checkbox }}
                    />
className={{ root: classes.checkbox }}

也正在错误。谢谢。

How can I change the root styles in Checkbox. This does not work.

 <CheckboxItem
                      onChange={()}
                      checked={isChecked}
                      label="Show Checkbox"
                      classes={{ root: classes.checkbox }}
                    />
className={{ root: classes.checkbox }}

is erroring out as well. Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2025-02-18 14:52:33

您可以使用sx属性(例如文档建议)进行此操作:

<Checkbox
  {...label}
  defaultChecked
  sx={{
    color: pink[800],
    '&.Mui-checked': {
      color: pink[600],
    },
  }}
/>

另一种方法可以创建样式的组件:

const CheckBoxStyled = styled(Checkbox)`
  root: {
    "&$checked": {
      "& .MuiIconButton-label": {
        color: "red",
        ...
      },
      ...
    }
  },
`;

<CheckBoxStyled checked value="TestValue" onChange={handleChange}/>

如果以上不是很大的帮助,请您提供更多有关您想要的信息的信息更改和MUI的版本,可能会给您发送一个有效的示例。

You can do it either using the sx property like the documentation suggests:

<Checkbox
  {...label}
  defaultChecked
  sx={{
    color: pink[800],
    '&.Mui-checked': {
      color: pink[600],
    },
  }}
/>

Another way you can create a styled component:

const CheckBoxStyled = styled(Checkbox)`
  root: {
    "&$checked": {
      "& .MuiIconButton-label": {
        color: "red",
        ...
      },
      ...
    }
  },
`;

<CheckBoxStyled checked value="TestValue" onChange={handleChange}/>

In case the above it's not a big help can you please provide some more info of what you want to change and the version of MUI and probably can send you a working sample.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文