-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[Select] Recent removal of .MuiSelect-root
class prevents specifically targeting root for only Select
#30225
Comments
.MuiSelect-root
class prevents specifically targeting root for only Select
Hi. I apologize for late reply. We are aware of this constraint. As you can see here, we think that this is rather a healthy constraint. I am against reverting the change we made in #29593 because providing the root class of |
Yes, I understand that but I would also reference this comment and argue that the hypothesis mentioned is not valid and there are in fact developers wanting to style them differently. I am not seeing the issue of allowing someone to style the Select root without styling the TextField root. Why would that be a concern? |
I strongly think that it's a very common use case to style them differently @hbjORbj are there any updates on it? |
I will add "waiting for upvotes" label to see the popularity of the opinion. |
@rathpc The |
Hey @hbjORbj, any update on this. I'd really love to just target select elements. |
In order to style the border, you need to target root and not just the select class and many other cases, so I agree with others' opinions to allow targeting the root |
In Typescript you only has to set the type of MuiSelect: {
styleOverrides: {
root: {
fontSize: '15px',
color: '#555555',
borderRadius: '8px',
borderColor: '#CCCCCC',
},
select: {
padding: '8px 32px 6px 12px'
}
} as any
} |
"any" leads to losing type completion in styleOverrides block. You can use this boilerplate: import type { Components, ComponentsOverrides, Theme } from "@mui/material";
import { OverridesStyleRules } from "@mui/material/styles/overrides";
type OverridesWithRoot = ComponentsOverrides<Theme>["MuiSelect"] & {
root: OverridesStyleRules<"root", "MuiSelect", Theme>["root"];
};
export const MuiSelect: Components<Theme>["MuiSelect"] = {
defaultProps: {
onClose: () => {
setTimeout(() => {
(document.activeElement as HTMLElement).blur();
}, 0);
}
},
styleOverrides: {
select: ({ ownerState, theme }) =>
theme.unstable_sx({
py: 2,
fontSize: 14,
border: "none !important",
borderRadius: 2.5
}),
root: ({ ownerState, theme }) =>
theme.unstable_sx({
".MuiOutlinedInput-notchedOutline": { border: 0 }
})
} as OverridesWithRoot
}; |
I stumbled upon this while going through our most upvoted issues. Turns out we fixed this (#44928) without knowing about #29593. I suspected something weird was going on: #42975 (review). We either:
We should go with option 1, IMO. I disagree with the following:
29 upvotes on this issue also disagree with this. This is on page 2 of our most upvoted issues. As additional info, the Autocomplete component does have a root class, but it's not the same as its input root. As a post-mortem, the reason we fixed it without noticing it was removed on purpose was:
What option should we follow @aarongarciah? |
@DiegoAndai I don't have a strong opinion and I'm not fully familiarized with how we handle this in all components, but looks like option 1 is what users want. If this is consistent with how we handle it in other components, no objections from my side. |
Duplicates
Latest version
Current behavior 😯
Following the merge of this PR into version 5.1.1, we can no longer specifically target the root element of a Select explicitly without also targeting all Inputs. Having this root class for example allowed you to be able to add different padding for a Select component at the root but not for other Inputs.
I understand it was removed as a result of also removing the
root
override slot because that usage was unclear - however I think we should still keep the class as that is useful for specificity purposes.Expected behavior 🤔
.MuiSelect-root
is still available as a class on the root element but the slot is not available to apply styleOverrides to.Steps to reproduce 🕹
Before Select root was removed (v5.1.0): codesanbox
After Select root was removed (v5.2.4): codesandbox
If you compare the two you will see that erroneous padding is present on the right side of the select in the "After" option because it is no longer able to target the Select root to override this.
Context 🔦
Without this root class style overrides get very complicated, very quickly if you are trying to apply varying styles to selects vs inputs vs multiline inputs and there are some styles you may not want just on the input element itself, but rather the wrapper (root). This has also broken our Select styles and prevented us from upgrading beyond 5.1.0 unless we do quite a bit of unconventional style hacking to get our theme back to where it was.
Your environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: