-
-
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
[InputLabel][material-ui] InputLabel supports ownerState.focused for styleOverrides #39470
[InputLabel][material-ui] InputLabel supports ownerState.focused for styleOverrides #39470
Conversation
Netlify deploy previewhttps://deploy-preview-39470--material-ui.netlify.app/ Bundle size reportDetails of bundle changes (Toolpad) |
...(props.ownerState.focused === true && { | ||
[`&.${classes.focused}`]: { | ||
color: colorRed, | ||
}, | ||
}), |
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.
Apparently color
isn't the best property to use here as it's the one property that has a specificity conflict with FormLabel
: https://github.com/mui/material-ui/blob/master/packages/mui-material/src/FormLabel/FormLabel.js#L47-L49
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.
Nice addition 🎉
Ported to v6 in #39483 |
It still looks a bit odd when you enter something into the field then tab to the next, the label then shrinks. It would be good to keep the I played around with the sandbox demo you made and figured out if you check the formControl.filled you can keep the full label up top when it is not focused. Since the only time you really want to shrink is when the label moves back down into the placeholder area. Hope this helps anyone else that finds this PR components: {
MuiInputLabel: {
styleOverrides: {
root: (props: any) => {
const hasValue = props.ownerState.formControl?.filled === true; // filled or not
return {
maxWidth: `calc(100% - ${props.ownerState.focused || hasValue ? 0 : 48}px)`,
};
},
},
},
}, |
Resolves #37069, Resolves #36550, Resolves #39427
This PR enables users to more easily customize the
maxWidth
of aTextField
's label based on it's focused state to control truncation of the labelThe before/after end result look same, but after this fix you are no longer required to manually add a focused state to achieve the customization, and it can be done in the theme
Before: https://codesandbox.io/s/https-github-com-mui-material-ui-issues-39427-vx2gvd?file=/demo.tsx
After: https://codesandbox.io/s/https-github-com-mui-material-ui-pull-39470-y7gr8x