Skip to content
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

[material] Add global CSS class for readOnly prop #32822

Merged
merged 11 commits into from
Feb 23, 2023

Conversation

jrparish
Copy link
Contributor

@jrparish jrparish commented May 18, 2022

Resolves #26488

This change provides a readOnly class to allow for targetted styling

image

@mui-bot
Copy link

mui-bot commented May 18, 2022

Netlify deploy preview

Bundle size report

Details of bundle changes

Generated by 🚫 dangerJS against 7b654f0

@ZeeshanTamboli ZeeshanTamboli changed the title [InputBase] Adds class for readOnly prop [InputBase] Add CSS class for readOnly prop May 19, 2022
@ZeeshanTamboli ZeeshanTamboli added new feature New feature or request component: text field This is the name of the generic UI component, not the React module! labels May 19, 2022
@mnajdova
Copy link
Member

mnajdova commented Jun 8, 2022

See #26488 (comment) we would need to add this component as a state class so that the name would be Mui-readOnly, not MuiInputBase-readOnly. You can start by adding it here - https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/generateUtilityClass/generateUtilityClass.ts and updating the tests and documentaiton around it.

Resolves mui#26488

This change provides a readOnly class to allow for targetted styling
@JP250552 JP250552 force-pushed the feature/mui-input-base-read-only branch from 737c967 to c323765 Compare June 16, 2022 13:34
@JP250552
Copy link

@mnajdova Thank you for the direction, I have updated the code accordingly along with an updated screenshot with the correct class name.

Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, one final comment to avoid breaking change in the Rating component.

@@ -57,7 +57,11 @@
"iconActive",
"decimal"
],
"globalClasses": { "disabled": "Mui-disabled", "focusVisible": "Mui-focusVisible" },
"globalClasses": {
"readOnly": "Mui-readOnly",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change we will need to manually add the MuiRating-readOnly in the Rating component, and add a comment to remove it in v6.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This diff could help:

index f0f2234850..de1020c23c 100644
--- a/packages/mui-material/src/Rating/Rating.js
+++ b/packages/mui-material/src/Rating/Rating.js
@@ -499,7 +499,14 @@ const Rating = React.forwardRef(function Rating(inProps, ref) {
       ref={handleRef}
       onMouseMove={handleMouseMove}
       onMouseLeave={handleMouseLeave}
-      className={clsx(classes.root, className)}
+      className={clsx(
+        classes.root,
+        {
+          // TODO v6: remove this class as it duplicates with the gloabl state class Mui-readOnly
+          'MuiRating-readOnly': readOnly,
+        },
+        className,
+      )}
       ownerState={ownerState}
       role={readOnly ? 'img' : null}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even with the suggested changes, it doesn't change the outcome of the rating.json file. I'm not sure what to do here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix, there was a spelling mistake in the useUtilityClasses.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ZeeshanTamboli would you like to finish this up and merge it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll do it.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 23, 2022
@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Aug 25, 2022

readOnly prop was added for Input in #33654 which was released. I think we can keep this PR open and add changes only for global Mui-readOnly state class.

@michaldudak
Copy link
Member

@jrparish are you still interested in completing this PR? As @ZeeshanTamboli noted, it should be a matter of handling the Mui-readOnly class.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Oct 12, 2022
@JP250552
Copy link

@michaldudak @ZeeshanTamboli Updated to only include class changes

@mnajdova
Copy link
Member

We should have added readOnly as a global classname in #33654, otherwise now we are changing the behavior in this PR (the classname would be Mui-readOnly instead of MuiInput-readOnly. We should do the switch in v6 in my opinion to avoid surprises or duplicate classes. (it's fine if we have both classes, but it would be confusing.

@mnajdova mnajdova added v6.x and removed new feature New feature or request labels Dec 20, 2022
@mnajdova mnajdova added package: material-ui Specific to @mui/material and removed component: text field This is the name of the generic UI component, not the React module! v6.x labels Feb 23, 2023
@mnajdova mnajdova changed the title [InputBase] Add CSS class for readOnly prop [material] Add global CSS class for readOnly prop Feb 23, 2023
@@ -498,7 +498,14 @@ const Rating = React.forwardRef(function Rating(inProps, ref) {
ref={handleRef}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
className={clsx(classes.root, className)}
className={clsx(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to apply similar patches in InputBase as there was quite some time since we added the read only class name.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@ZeeshanTamboli ZeeshanTamboli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did the remaining changes. @jrparish Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[InputBase] - Add Mui-readOnly class
6 participants