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

[Container] Fix support of custom breakpoint units #23191

Merged
merged 4 commits into from Oct 21, 2020

Conversation

espipj
Copy link
Contributor

@espipj espipj commented Oct 21, 2020

When setting breakpoints in different units (like for example em) the media-query/breakpoints get created properly and they use the units defined.
However, the Container component is still using no units at all (defaults to pixels) which makes everything break apart.
image

This PR should fix it, but I've found out another bug on the ThemeProvider which I may need help with. The units set are not showing up on it at theme.breakpoints.unit so on the generated CSS it shows up like undefined:
image
On the React DevTools the Theme provider doesn't show units defined...
image

If I manually set unit: "em" under breakpoints through the DevTools, it magically works after that!
image

So basically some tweaks need to be made to the ThemeProvider to make it work, but I can't find where (need some guidance).

@mui-pr-bot
Copy link

mui-pr-bot commented Oct 21, 2020

Details of bundle changes

Generated by 🚫 dangerJS against 017b0a3

@oliviertassinari oliviertassinari changed the title Container improvements in accesibility [Container] Fix support of custom breakpoint units Oct 21, 2020
@espipj
Copy link
Contributor Author

espipj commented Oct 21, 2020

Hey thanks for that, I couldn't spot the Theme thing and I was getting mad! 😃

@oliviertassinari oliviertassinari merged commit c60fbba into mui:next Oct 21, 2020
};
}
return acc;
}, {}),
/* Styles applied to the root element if `maxWidth="xs"`. */
maxWidthXs: {
[theme.breakpoints.up('xs')]: {
maxWidth: Math.max(theme.breakpoints.values.xs, 444),
maxWidth: Math.max(`${theme.breakpoints.values.xs}${theme.breakpoints.unit}`, 444),
Copy link
Contributor Author

@espipj espipj Oct 22, 2020

Choose a reason for hiding this comment

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

Hey! Not sure about this line, I think it is likely to break:
image
I guess this would work:
maxWidth: `${Math.max(theme.breakpoints.values.xs, theme.breakpoints.unit.endsWith('em') ? 27.75 : 444)}${theme.breakpoints.unit}`,

27.75 comes from dividing 444 / 16 (default font size in browsers).

PS: The syntax is a bit clunky lol

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am happy to push this changes and open a new PR if there's no other way now that it is merged 😄

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for double checking. It's definitely broken.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

What do you think about simply not handling the case, going back to the previous logic?

Copy link
Member

Choose a reason for hiding this comment

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

xs is designed to be 0, IMHO, the existing of 444 in the first place is wrong

Copy link
Contributor Author

@espipj espipj Oct 23, 2020

Choose a reason for hiding this comment

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

Yes xs was designed to be 0 as it is the smallest breakpoint. But in the case of defining containers maxWidth as this case is a 0 won't be a good value I guess that's why the 444 is there. The fix proposed what it does is that it will set the value either to 444px or 27.5em/rem depending on the units being used, or if the breakpoint is different from the default and bigger than 444px/27.5em it will take it as maxWidth which is what the other maxWidth (sm,md,lg...) do...
So when using:

      <Container maxWidth={"xs"}>
        {children}
      </Container>

For the width of the container it will use by default 444px when setting the breakpoints with no units or with pixels. An will use 27.5em for it if they are set in ems...
If we just leave it as it is... It will default use 444px which works for pixels but it won't work well for em/rem units...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still It is a codebase which I've recently started working with it and I might be missing something... I think is worth asking someone else in the MUI team to double check what we are discussing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see now that this bug (at least for sm, md, lg, xl) is showing up across the codebase in some other places... i.e: Dialog Component

Copy link
Member

Choose a reason for hiding this comment

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

The case of the Dialog is even harder to handle, I doubt we can solve it without custom overrides.

@espipj
Copy link
Contributor Author

espipj commented Oct 22, 2020

Hello!

Apart from the changes above.
When would this be released (I am not really aware of the release process)? Would it be released directly to 5.X (alpha) or is there any chance that this changes could be pushed into a 4.x release?
Thanks for the amazing work 😺

This whole PR is related to #21476

@oliviertassinari
Copy link
Member

@espipj The changes will be released before the end of the week in v5-alpha.14. We only backport critical issues. This isn't one.

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: Container The React component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants