New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[base] Make CSS class prefixes consistent #33411
Merged
Merged
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
9ed8620
[base] Make CSS class prefixes consistent
michaldudak 06f6b49
Fix unit tests
michaldudak 4dfa187
Merge branch 'master' into consistent-classes
michaldudak 4d63740
Rename all Base- classes to Mui- and add Mui-Base product class
michaldudak e3c5339
Add product class to Material UI components
michaldudak 2d75867
Do not export generateUtilityClass from Base
michaldudak 35010b0
Fix TS errors
michaldudak 4166ffb
Fix tests
michaldudak 1d9dedd
Fix lint errors
michaldudak f683f20
Fix API docs generation
michaldudak c7d5d97
Do not reexport Base's generateUtilityClass from Material UI
michaldudak 5e56e7b
Merge remote-tracking branch 'upstream/master' into consistent-classes
michaldudak aa63bbb
Change product classes to Mui-product
michaldudak 895a882
Use @mui/material generateUtilityClass in lab and material-next
michaldudak 81b4026
Don't use hardcoded classes in tests
michaldudak fc66d45
Merge branch 'master' into consistent-classes
michaldudak 4a7c414
Merge branch 'master' into consistent-classes
michaldudak 61babab
Do not generate product-specific classes
michaldudak File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect
here so I don't have to think about what's going to be the class name when I'm looking at my code (
import { InputUnstyled } from "@mui/material"
). Commented in #33260 (comment).Also, notice the company name
Mui
prefix to avoid class name collisions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've discussed it already in the past (last year, possibly?) and settled on BaseComponentName. If I remember correctly the arguments for Base* over *Unstyled were that:
.ButtonUnstyled { color: green; }
- it was brought up by @mnajdova.As for the "Mui" prefix - I'm ok with adding it. It'll make the class names a bit longer, but if you think it's important to have the company name there, I won't oppose it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember a notion page about changing the name of the npm package so that it would feel more natural to expose headless components and hooks from
@mui/base
compared to@mui/unstyled
, I think that it was also about covering the use case of the package, more than being descriptive of the content of the npm package.Maybe there is another discussion about this for the components not the npm package that I wasn't involved in.
Ok, but assuming we change the name of the components from Unstyled to Base (and find a way to fix the conflict with Base Material UI components, e.g. ButtonBase that is styled), I still don't think that the changes proposed in this PR work. I think that it should be all-in: replace unstyled to base, everywhere at once and expose a codemod to handle it. I think that developers will be confused to have Unstyled sometimes and Base some other times when using MUI Base.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming components from
*Unstyled
toBase*
wasn't on the table right now (and I'm not convinced we should do this - I feel everyone agreed on*Unstyled
). It's just about CSS classes.See #31974 (comment) for the discussion I found (cc @mnajdova). I remember talking about it in one of the meetings also, but could not find anything in the notes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like what we are missing is giving a bit of background on why the change is being done in the PR description.
From different discussions here and there and things that I could remember we had this:
Mateiral UI components are named as MuiComponentName. When we started with Joy we had the same pattern, until we realized that having the same classes in Material UI and Joy components can be problematic, because they are not unique. This is why we decided to prefix the Joy components with Joy instead of Mui. In the mean time, the unstyled components were following this so-called pattern, of using MuiComponentName (without the Unstyled suffix, because the CSS would feel weird if it looked like:
.MuiSomethingUnstyled: { color: red } // it's not unstyled anymore
). Now that the Joy components are changed, it looks like the pattern is :ProductComponentName
, instead ofCompanyComponentName
, hence the changes proposed on this PR.I would vote for keeping what we have in this PR going forward, but I agree that this should not be something rushed up and released without clear rationales.
In addition to this, I would keep both classes for couple of versions giving people time to migrate to the new classes (in case if they haven't used the
componentNameClasses
constants).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it would be awesome to take these dimensions #33260 (comment) and compare how each of the different options that we have performs. I'm slowing down the decision process a bit because I feel that we are touching "customization", one of the biggest challenges that developers have https://mui.com/blog/2021-developer-survey-results/#what-else-can-we-do-to-improve-mui-for-you and 2. the decision feels hardly reversible 3. it went a bit against the expectation I had, creating confusion, hence maybe it could against the intuition of existing users.
Starting a bit quickly. Here are the different options that seem to emerge. Guess what's the class name of the thumb slot:
A.
CompanyComponentName
My initial assumption was that we were following this. I like how it's always the same. Sharing Mui between different products which might help us communicate that Joy and Material should be seen as themes for business users and that Material UI !== MUI. Otherwise, changing the Mui prefix to Md could be also a great way to communicate the latter point but not the former point. For developers that want to apply global CSS to customize the components => we would have to tell them: don't, it's a foot gun, would they do it, yeah maybe they would anyway.
B. Current tradeoff
Is not fully followed in HEAD, which we could scope down #33260 to
C.
ProductComponentName
or
sliderUnstyledClasses.thumb = 'BaseSlider-thumb'
feels surprising, my first thought was, wait, why?D.
CompanyModuleExportName
I like how it feels predictable, but I don't like how some of the unstyled components are re-exported as is from Joy UI or Material UI and hence would require us to find a way to customize the class names, seems too much overhead to implement in production to stay clear & predictable.
What's best? It's off my hands at this point, I have tried to share all of my thoughts on this, and I trust we will pick something that maximizes "simplicity".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A.
CompanyComponentName
Why would you like to limit this way of customization? If someone prefers this way (as it's likely the easiest and doesn't require any styling libraries or preprocessors), I would let them.
B. Current tradeoff
To me option B is a no-go - why would Material and Base have the same prefix and Joy another one? It would confuse people.
C.
ProductComponentName
We can discuss the prefixes for each product. I don't insist on the prefix for MUI Base components to be
Base
D. CompanyModuleExportName
This solution creates the longest class names.
It's a problem present in C as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Of all the options here, I like A the best for the sake of simplicity. I also really like it from a branding angle, reinforcing MUI as a brand vs its products, while also showcasing the ways in which they are comparable and to some extent interchangeable.
The only thing that feels a bit incongruous to me is the fact that we useOn second thought I guess it doesn't necessarily break the pattern. It's just maybe not obvious that Unstyled = Base.Unstyled
when referring to Base components—if I'm following the pattern ofsliderMdClasses
andsliderJoyClasses
then I would expect to seeSliderBase
andsliderBaseClasses
rather thansliderUnstyledClasses
. In other words, there's an extra step required to understand that Unstyled = Base. It's minor, but it feels like it breaks the pattern.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaldudak I think that the reasoning goes the other way around: What do we gain by dropping this support? Are there more pros than cons?
I agree it's weird, and a convention harder to learn for developers.
I don't see this problem in D, maybe only because I have renamed the exports to avoid JavaScript variable conflicts in the example? In practice, developers won't do it like this, maybe I should haven't have renamed the exports after import 😁
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are moving the discussion back to #33260.