-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
[DatePicker] Make the month drop-down from CalendarPicker available in sx #6218
Comments
Hello @TheRealCuran I've tried replicating your case in web and was able to solve the issue with a very similar solution to your expected one: sx={{
'& .MuiPickersCalendarHeader-label': {
fontSize: 'initial',
},
}} Could you confirm if it solves your issue? |
Hey @LukasTy , My <DatePicker
sx={{
'& .MuiPickersCalendarHeader-label': {
fontSize: 'initial',
},
}}
ampm={false}
inputFormat="MM/yyyy"
mask="__/____"
views={['year', 'month']}
renderInput={({ InputProps, ...params }) => (
<TextField
{...params}
InputProps={{
...InputProps,
endAdornment: (
<React.Fragment>
{this.props.searchOptions.fromDate && (
<IconButton onClick={(e) => {
e.stopPropagation();
actions.searchSelectFrom(null);
}}
>
<Clear />
</IconButton>
)}
{InputProps?.endAdornment}
</React.Fragment>
),
}}
/>
)}
aria-label="select start date"
value={this.dateFromEpoch(this.props.searchOptions.fromDate)}
onChange={newDate => actions.searchSelectFrom(newDate.valueOf())}
/> But maybe I am doing something really wrong here? If I move this to the theme it works again, which is already an improvement, since I get rid of the experimental Apart from that: I can't find the CSS class |
@TheRealCuran Sorry for causing confusion with If you need it fixed globally in your application, I would say that using a
Yes, we are aware of this shortcoming as we did not update the documentation to include all the possible pickers sub-components, which are now style-able/overridable. |
Yeah, that is basically what this feature request is about: provide a way to style those dynamic parts too through
That would be much appreciated, I had other issues, where I only found the missing documentation part somewhere in a ticket or elsewhere.
This app is sadly still purely JS and while I do have a branch converting it to TS, that one needs a lot more work (mostly because it is the best time to get rid of some other technical debt as well). But thanks for the suggestion. |
I'm just curious to know—do you specifically need to have different styles through the application? Because the TL.DR.:
|
Yeah, I do need the ability to style this individually and would appreciate the And I think what is missing here (and probably other places) is, that |
I see, in such case, I'd say that your best bet with the current implementation is the following snippet: // overrides style in desktop version
PaperProps={{
sx: {
'.MuiPickersCalendarHeader-label': {
fontSize: 'initial',
},
},
}}
// overrides style in mobile version (if you need it)
DialogProps={{
sx: {
'.MuiPickersCalendarHeader-label': {
fontSize: 'initial',
},
},
}} As you can see, this case helped in discovering an inconsistency— |
Thanks! Yeah, that looks good. I leave it up to you if you want to keep this request open or not. I can see arguments for both solutions being "better". Pushing this into the export const MyStyledComp = styled(MyStyledCompImpl, {
name: 'MyStyledComp',
slot: 'Root',
})<MyStyledCompProps>(({ theme }) => ({
'& .MyStyledComp-active': {
// some props here
'&:hover': {
// some other props here
}
},
})) |
I'm not sure it would be the best approach to add a prop for basically every different component. Do you see any possible non-intrusive improvement for this case @alexfauquette @flaviendelangle ? |
This no longer seem like a problem as we can easily target all slots and pass the slotProps={{
layout: {
sx: {
".MuiPickersCalendarHeader-label": {
fontSize: "inherit"
}
}
}
}} |
Duplicates
Latest version
Summary 💡
I maintain an Electron app, that sets a global
![image](https://user-images.githubusercontent.com/3419202/191089569-46bffbf1-49f0-4f5a-b858-cec6b17d89c9.png)
fontSize
of1.3rem
. This size propagates to the font size of the text in the month drop-down of the<CalendarPicker />
component, making it overflow:I thought it would be easy fixing this, by adding a
![image](https://user-images.githubusercontent.com/3419202/191090631-c855567a-cf25-4e2c-addf-6ebd22fbb2c7.png)
sx
property to my<DatePicker />
and (re-)set thefontSize
to a better value for this particular component. However I didn't manage to address the<CalendarPicker />
, since it gets created dynamically and especially since there is a<div>
with therole="presentation"
that overwrites any value you might assign to& .MuiCalendarPicker-root
:I did try stuff like:
but as I said, that never got applied, since the component is inserted dynamically (AFAICT).
In the end I put the above snippet into the theme (which is OK for me, since I only have these pickers in one view and the size issue applies to all of them anyway):
I would love to have a way to set this in my
<DatePicker>
'ssx
property. I imagine something like this:This also applies to
.MuiCalendarPicker-root
, because if that was reachable, it would be possible to force thefontSize
in any case.Examples 🌈
This is how I want it to look:
![image](https://user-images.githubusercontent.com/3419202/191091527-8d107fa0-1f48-4f8b-81be-54e6240c7710.png)
Motivation 🔦
I had to abuse the theme to style a particular component. And if I had to do different sizes for different pages I would already have to work with two themes, introduce styled components, etc. to change the value of one sub-component properties style.
Order ID 💳 (optional)
47016
The text was updated successfully, but these errors were encountered: