Material-ui: Button disabled gets twice class Mui-disabled

Created on 13 Feb 2020  路  11Comments  路  Source: mui-org/material-ui

When a Button is disabled, it gets twice the class Mui-disabled.

unknown-20

  • [x] The issue is present in the latest release.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

There are two Mui-disabled class on a disabled Button.

Expected Behavior 馃

Only one Mui-disabled class on a disabled Button.

Steps to Reproduce 馃暪

https://material-ui.com/components/buttons/
Or: https://codesandbox.io/s/material-demo-mtk0k

Steps:

  1. Inspect the disabled Button

Context 馃敠

Doesn't affect behavior.

Your Environment 馃寧

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.9.2 |
| React | v16.12.0 |
| Browser | Version 78.0.3904.87 (Official Build) (64-bit) |
| TypeScript | 3.9.0 |

core discussion

Most helpful comment

Is there a reason this closed? This clearly isn't the intended behavior. There shouldn't be two .Mui-disabled classes appended to a DOM node if there is only one disabled prop on the component. It seems to be a real bug and not-intended behavior. @eps1lon Can we re-open?

All 11 comments

Kind of a general question I have about pseudo-class classnames @oliviertassinari.

If these are passed along to child components that also have these classes how are the styles reconciled?

I thought it was a duplicate but I can't find it.
What's the concern? We could be using a data-disabled attribute instead (reach ui way), it would work identically. The advantage of a class name is that developers can easily toggle it in the dev tools, close to the approach Bootstrap uses (50% of our users are coming from Bootstrap based on our last survey?), and the syntax is "lighter" when used it in a selector.

What's the concern?

ButtonBase declaring styles for disabled as well as Button. Since both have the same classname which styles are used?

and the syntax is "lighter" when used it in a selector.

I thought we didn't support this anyway since the classnames might get optimized in production?

.Mui-disabled is a global class name, it's meant to be used. The equivalent in Bootstrap is .disabled.
If we were using a data- attribute, we would get the merge happen seamlessly. We concanate the class names, so it behave differently for us. I'm not aware of any potential bug it can cause.

Right, we don't support styles in .disabled only .some-other-class.disabled.

I think this is fine. It's not worth spending time evaluating this at runtime to strip duplicate classnames unless there's an actual bug.

The mean of that report was about cleanness as there is no impact, there is just a duplicate class for no reason.

Is there a reason this closed? This clearly isn't the intended behavior. There shouldn't be two .Mui-disabled classes appended to a DOM node if there is only one disabled prop on the component. It seems to be a real bug and not-intended behavior. @eps1lon Can we re-open?

@xenostar Why does it matter?

@oliviertassinari

It seems I can't override the disabled state of the button anymore when the Mui-disabled is applied twice.

My custom makeStyle-disabled-104 class gets between the two definitions and color prop gets overridden by the second Mui-disabled class.

image

<Button
  fullWidth
  disabled={amPm === 'AM'}
  classes={{
    root: classes.selected,
    disabled: classes.disabled,
  }}>
  AM
</Button>

A valid workaround is to use !important but it will be awesome to have a generic solution to the problem.

@kachar The order of the class names in the attribute doesn't matter for specificifiy.

I start to think that we should remove all the pseudo-classes from the classes API so developers are forced to use &.Mui-disabled, which will have the correct specificity, cc @mnajdova.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zabojad picture zabojad  路  3Comments

sys13 picture sys13  路  3Comments

FranBran picture FranBran  路  3Comments

ericraffin picture ericraffin  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments