mui / mui/material-ui

[Checkbox] Overriding Checkbox styles from theme provider not working

Open
#34,708 2 comments 0 reactions 1 assignee View on GitHub

@mnajdova is already working on this.

Since Oct 11, 2022.

breaking change docs scope: checkbox v8.x
Dominant language
JavaScript
Stars
99.1k
Forks
32.5k
Avg merge
2d 17h
Merged PRs (30d)
106

Description

Duplicates
  • I have searched the existing issues
Latest version
  • I have tested the latest version
Steps to reproduce 🕹

Steps:

  1. Create a theme
  2. Add MuiCheckbox to components
  3. Override styles for checked
Current behavior 😯

I want to override the checked and disabled of the CheckBox component as described in the Checkbox API

I have the following code, which is imported in the theme, in the components section. That works fine

import { Components, Theme } from '@mui/material';

export const MuiCheckbox: Components<Theme>['MuiCheckbox'] = {
  defaultProps: {
    disableRipple: true
  },
  styleOverrides: {
    root: ({ theme }) => ({
      borderRadius: 0
      // Here it works but it will override all of the styles which I don't want
      /* '&.Mui-checked': {
        color: '#ff0000'
      }*/
    }),
    checked: ({ theme }) => ({
      // This doesn't work
      color: '#ff0000'
    })
  }
};

The checked does not work in my example. I don't get the desired result, the color should be #ff0000 in this case. But it's still the theme.primary

first

In the root with &.Mui-checked it works.

second

Expected behavior 🤔

Selectors for checked should work as well.

The checked should be able to set the style

Context 🔦

No response

Your environment 🌎
npx @mui/envinfo
  Tested on Chrome, Edge, Opera - not related to browser
  System:
    OS: Linux 5.10 Ubuntu 20.04.4 LTS (Focal Fossa)
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: Not Found
    Firefox: Not Found
  npmPackages:
    @emotion/react: 11.9.3 => 11.9.3
    @emotion/styled: 11.9.3 => 11.9.3
    @mui/core-downloads-tracker:  5.10.8
    @mui/icons-material: 5.8.4 => 5.8.4
    @mui/material: 5.10.8 => 5.10.8
    @types/react: 17.0.3 => 17.0.3
    react: 17.0.2 => 17.0.2
    react-dom: 17.0.2 => 17.0.2
    typescript: 4.3.5 => 4.3.5

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.