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-ui][Input] Remove unused classes from InputClasses interface #44987

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jan 10, 2025

This PR removes unused classes from InputClasses interface, removed classes doesn't actually end up in dom and just present in interface, added tests to verify same

I found this while working on deprecating composed classes for Input component

@sai6855 sai6855 added bug 🐛 Something doesn't work package: material-ui Specific to @mui/material labels Jan 10, 2025
@mui-bot
Copy link

mui-bot commented Jan 10, 2025

Netlify deploy preview

https://deploy-preview-44987--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 3b6b2a9

@sai6855 sai6855 requested a review from aarongarciah January 10, 2025 06:14
@aarongarciah aarongarciah requested review from siriwatknp and removed request for aarongarciah January 10, 2025 08:31
@sai6855 sai6855 added the component: text field This is the name of the generic UI component, not the React module! label Jan 10, 2025
/** Styles applied to the root element if the component is focused. */
focused: string;
/** Styles applied to the root element if `disabled={true}`. */
disabled: string;
/** Styles applied to the root element if color secondary. */
colorSecondary: string;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of adding the class to the DOM, I chose to remove it here. The fact that no users have reported this issue, even though it has likely existed for a long time (possibly since v5), suggests that it is not widely used. Therefore, I decided to remove the class instead of adding it to the DOM.

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.

@sai6855 I see there are several unused classes in the Input component, such as sizeSmall, inputSizeSmall, multiline, inputMultiline, inputAdornedStart and others. Only these classes are actually used: root, focused, error, disabled, underline, and input.

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 13, 2025

@sai6855 I see there are several unused classes in the Input component, such as sizeSmall, inputSizeSmall, multiline, inputMultiline, inputAdornedStart and others. Only these classes are actually used: root, focused, error, disabled, underline, and input.

Thanks!! Yeah you are right, removed all usused classes and added tests to verify same

@ZeeshanTamboli
Copy link
Member

@sai6855 I looked into the history of this and found that InputBase classes can also be targeted by Input, FilledInput, and OutlinedInput classes.

The utility classes are passed to the InputBase component. For example, in the Input component, the classes are forwarded to InputBase:

Additionally, the InputBase class types are spread:


This applies to FilledInput and OutlinedInput as well. For example, in #31080, it was expected that styles for Input with multiline are applied using inputClasses.multiline instead of inputBaseClasses.multiline, even though the actual DOM classname is MuiInputBase-multiline. This was fixed in #31186.

I think this PR should be closed, as removing these classes would introduce a breaking change.

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 13, 2025

@ZeeshanTamboli i agree it's a breaking change if classes are removed, what do you think of last 2 commits? it keeps class in interface but removes info from docs so that users cannot see wrong info on classes

@ZeeshanTamboli
Copy link
Member

@sai6855 If those class names are still used for styling, why remove them from the docs?

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 13, 2025

@sai6855 If those class names are still used for styling, why remove them from the docs?

take this class for example https://mui.com/material-ui/api/input/#input-classes-MuiInput-colorSecondary

From user pov, user sees this class and tries to style using this class but it doesn't work because this class doesn't exist. so removing this info makes sense know?

@ZeeshanTamboli
Copy link
Member

ZeeshanTamboli commented Jan 13, 2025

but it doesn't work

It does work. Check this example: https://codesandbox.io/p/sandbox/purple-violet-sgk8hf. Type in the input, and you'll see the text color is red. Although the DOM shows the class as MuiInputBase-colorSecondary, we're using inputClasses.secondary (MuiInput-colorSecondary).

It's what I said in #44987 (comment) that the classes are forwarded to the InputBase.

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 13, 2025

but it doesn't work

It does work. Check this example: https://codesandbox.io/p/sandbox/purple-violet-sgk8hf. Type in the input, and you'll see the text color is red. Although the DOM shows the class as MuiInputBase-colorSecondary, we're using inputClasses.secondary (MuiInput-colorSecondary).

It's what I said in #44987 (comment) that the classes are forwarded to the InputBase.

It does work.

I think there is slight misunderstanding going on here, provided example works because it is using inputClasses.colorSecondary which is equivalent to .MuiInputBase-colorSecondary not .MuiInput-colorSecondary, if component is styled using .MuiInput-colorSecondary it doesn't work because there is no such class in DOM.

this commit 89a2570 removes below info from docs which is saying to use .MuiInput-colorSecondary

image

I tried to demonstrated same in this demo https://stackblitz.com/edit/react-2kfct41z?file=Demo.tsx

@ZeeshanTamboli
Copy link
Member

@sai6855 Ah, I see now. I was confused about how inputClasses.secondary targeted MuiInputBase-colorSecondary. It turns out inputClasses.secondary maps to MuiInputBase-colorSecondary, not MuiInput-colorSecondary, which isn’t applied in the DOM.

So, it makes sense to remove it from the docs. Alternatively, we could mark it as deprecated since developers are already using it. Either way, we should get a review from @DiegoAndai on this.

@sai6855
Copy link
Contributor Author

sai6855 commented Jan 16, 2025

@DiegoAndai Here's the summary of above discussion

There are several classes in Input classes API documentaion that doesn't work because these classes doesn't end up in DOM.
One such example is this https://mui.com/material-ui/api/input/#input-classes-MuiInput-colorSecondary

proof for .MuiInput-colorSecondary is not working: https://github.com/mui/material-ui/pull/44987/files#diff-a91d61a487c6fd5c001cd5cf45a1ab5393cdcd9c0efaf87c72b9b1eb5b3eefd2R54

This PR aims to remove any information regarding unused classes, we could try 2 ways to solve this

  1. Remove colorSecondary from InputClasses interface
    /** Styles applied to the root element if color secondary. */
    colorSecondary: string;
    , but this would be breaking change for users who are using inputClasses.colorSecondary
  2. Add @ignore in classes JSDoc which removes class related info from docs (Right now, i've implemented this)

which approach do you suggest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: text field This is the name of the generic UI component, not the React module! package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants