Material-ui: Duplicate class name in tag

Created on 2 Oct 2019  路  9Comments  路  Source: mui-org/material-ui

This is my snapshot v4.4.3 vs 4.5.0
In class name, we have duplicated item

Screen Shot 2019-10-02 at 2 07 46 PM

Screen Shot 2019-10-02 at 2 08 06 PM

| Tech | Version |
| ----------- | ------- |
| Material-UI | v4.5.0 |
| React |v16.10.1 |
| Browser |Chrome |
| TypeScript | no |
| etc. | |

bug 馃悰 Button good first issue

Most helpful comment

I can take this

All 9 comments

We must rollback to v4.4.3?

If it's causing you a problem, then yes, until it gets fixed.

Does it mean we should go for?

diff --git a/packages/material-ui/src/Button/Button.js b/packages/material-ui/src/Button/Button.js
index daf666872..7ef8e42d8 100644
--- a/packages/material-ui/src/Button/Button.js
+++ b/packages/material-ui/src/Button/Button.js
@@ -272,8 +272,8 @@ const Button = React.forwardRef(function Button(props, ref) {
       className={clsx(
         classes.root,
         classes[variant],
-        classes[`${variant}${color !== 'default' && color !== 'inherit' ? capitalize(color) : ''}`],
         {
+          [classes[`${variant}${capitalize(color)}`]]: color !== 'default' && color !== 'inherit',
           [classes[`${variant}Size${capitalize(size)}`]]: size !== 'medium',
           [classes[`size${capitalize(size)}`]]: size !== 'medium',
           [classes.disabled]: disabled,

I can take this

@netochaves sure :)

Why mix two variants of clsx arguments, why not just stick to one:

        classes.root,
        classes[variant],
        {
          [classes[`${variant}${capitalize(color)}`]]: color !== 'default' && color !== 'inherit',
          [classes[`${variant}Size${capitalize(size)}`]]: size !== 'medium',
          [classes[`size${capitalize(size)}`]]: size !== 'medium',
          [classes.disabled]: disabled,
          [classes.fullWidth]: fullWidth,
          [classes.colorInherit]: color === 'inherit',
        },
        className,

vs

        classes.root,
        classes[variant],
        color !== 'default' && color !== 'inherit' && classes[`${variant}${capitalize(color)}`],
        size !== 'medium' && classes[`${variant}Size${capitalize(size)}`],
        size !== 'medium' && classes[`size${capitalize(size)}`],
        disabled && classes.disabled ,
        fullWidth && classes.fullWidth ,
        color === 'inherit' && classes.colorInherit,
        className,

@croraf Is because 99% of the codebase already uses this approach a good answer? Alternatively, compare the readability of the two provided examples.

@oliviertassinari For me, more readable is the second one, as it is consistent. I'm not clear of what is the convention we follow when we put something in the object vs something as a plain argument?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

revskill10 picture revskill10  路  3Comments

sys13 picture sys13  路  3Comments

TimoRuetten picture TimoRuetten  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments

newoga picture newoga  路  3Comments