question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Slider] Customize disabled state

See original GitHub issue

I have overridden the disabled state of Slider.

but I don’t know which syntax is correct:

const theme = createMuiTheme({
  components: {
    MuiSlider: {
      styleOverrides: {
        root: {
           // case 1: Working
          // "&.MuiSlider-root.Mui-disabled": {
          //   color: "red"
          // }

          // case 2: Not Working
          "&.Mui-disabled": {
            color: "red"
          }
        }
      }
    }
  }
});

Usually, I use method 2. but it doesn’t seem to work in this case

More details:

https://codesandbox.io/s/continuousslider-material-demo-forked-3qphg

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
mnajdovacommented, Apr 16, 2021

Agree, I’ll handle it next week

1reaction
oliviertassinaricommented, Apr 16, 2021

@mnajdova It works, you are right. So it’s not only an issue with the Button but with all the components. e.g. in the slider so the color wins over the root.

diff --git a/packages/material-ui/src/Slider/Slider.js b/packages/material-ui/src/Slider/Slider.js
index f2fd1ff942..7ae62e11bc 100644
--- a/packages/material-ui/src/Slider/Slider.js
+++ b/packages/material-ui/src/Slider/Slider.js
@@ -37,10 +37,10 @@ const overridesResolver = (props, styles) => {

   const marked = marks.length > 0 && marks.some((mark) => mark.label);

-  return deepmerge(
+  return deepmerge(styles.root || {},
     {
       ...styles[`color${capitalize(styleProps.color)}`],
-      [`&.${sliderClasses.disabled}`]: styles.disabled,
+      [`&.${sliderClasses.disabled}`]: {...styles.disabled},
       ...(marked && styles.marked),
       ...(styleProps.orientation === 'vertical' && styles.vertical),
       ...(styleProps.track === 'inverted' && styles.trackInverted),
@@ -56,7 +56,6 @@ const overridesResolver = (props, styles) => {
         [`&.${sliderClasses.disabled}`]: styles.disabled,
       },
     },
-    styles.root || {},
   );
 };

I would personally prefer option 3. It seems simpler, maybe a bit faster at runtime and prevent developer to mix nested selectors in the root with a slot. They have to pick one approach, which should avoid footguns:

diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js
index cf52016d61..a112f3548b 100644
--- a/packages/material-ui/src/Button/Button.js
+++ b/packages/material-ui/src/Button/Button.js
@@ -13,27 +13,25 @@ import buttonClasses, { getButtonUtilityClass } from './buttonClasses';
 const overridesResolver = (props, styles) => {
   const { styleProps } = props;

-  return deepmerge(
-    {
-      ...styles[styleProps.variant],
-      ...styles[`${styleProps.variant}${capitalize(styleProps.color)}`],
-      ...styles[`size${capitalize(styleProps.size)}`],
-      ...styles[`${styleProps.variant}Size${capitalize(styleProps.size)}`],
-      ...(styleProps.color === 'inherit' && styles.colorInherit),
-      ...(styleProps.disableElevation && styles.disableElevation),
-      ...(styleProps.fullWidth && styles.fullWidth),
-      [`& .${buttonClasses.label}`]: styles.label,
-      [`& .${buttonClasses.startIcon}`]: {
-        ...styles.startIcon,
-        ...styles[`iconSize${capitalize(styleProps.size)}`],
-      },
-      [`& .${buttonClasses.endIcon}`]: {
-        ...styles.endIcon,
-        ...styles[`iconSize${capitalize(styleProps.size)}`],
-      },
+  return ({
+    [`& .${buttonClasses.label}`]: styles.label,
+    [`& .${buttonClasses.startIcon}`]: {
+      ...styles.startIcon,
+      ...styles[`iconSize${capitalize(styleProps.size)}`],
     },
-    styles.root || {},
-  );
+    [`& .${buttonClasses.endIcon}`]: {
+      ...styles.endIcon,
+      ...styles[`iconSize${capitalize(styleProps.size)}`],
+    },
+    ...styles.root,
+    ...styles[styleProps.variant],
+    ...styles[`${styleProps.variant}${capitalize(styleProps.color)}`],
+    ...styles[`size${capitalize(styleProps.size)}`],
+    ...styles[`${styleProps.variant}Size${capitalize(styleProps.size)}`],
+    ...(styleProps.color === 'inherit' && styles.colorInherit),
+    ...(styleProps.disableElevation && styles.disableElevation),
+    ...(styleProps.fullWidth && styles.fullWidth),
+  });
 };
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Slider] Customize disabled state #25075 - mui/material-ui
I have overridden the disabled state of Slider. but I don't know which syntax is correct: const theme = createMuiTheme( ...
Read more >
Enable & disable states in Flutter Slider widget - Syncfusion
Learn here all about the enabled and disabled states of the Syncfusion Flutter Slider (SfSlider) widget and how to customize them.
Read more >
noUiSlider - Disabling, Updating and Styling - Refreshless.com
In-dept details on disabling slider handles, updating options and styling noUiSlider. ... CSS can be used to show the disabled state.
Read more >
How to change material-ui slider thumb style when it's disabled
This is withStyle solution , where user can change the styling of slider and its sub component. Share.
Read more >
Disabled State - Slider - Kendo UI for Angular - Telerik
You can enable or disable the Slider. To disable the component, set the disabled property to true . Example. View Source.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found